Skip to content

Commit 56ae0c4

Browse files
author
Soroosh Sarabadani
committed
move test to the annotation package as well
1 parent 8a03936 commit 56ae0c4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

operator-framework/src/main/java/io/javaoperatorsdk/operator/processing/annotation/ControllersResourceWriter.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import static io.javaoperatorsdk.operator.ControllerUtils.CONTROLLERS_RESOURCE_PATH;
1414

15-
public class ControllersResourceWriter {
15+
class ControllersResourceWriter {
1616
private Map<String, String> mappings = new ConcurrentHashMap<>();
1717
private final ProcessingEnvironment processingEnvironment;
1818

@@ -26,7 +26,8 @@ public ControllersResourceWriter loadExistingMappings() {
2626
.getFiler()
2727
.getResource(StandardLocation.CLASS_OUTPUT, "", CONTROLLERS_RESOURCE_PATH);
2828

29-
final var existingLines = new BufferedReader(new InputStreamReader(readonlyResource.openInputStream()))
29+
final var bufferedReader = new BufferedReader(new InputStreamReader(readonlyResource.openInputStream()));
30+
final var existingLines = bufferedReader
3031
.lines()
3132
.map(l -> l.split(","))
3233
.collect(Collectors.toMap(parts -> parts[0], parts -> parts[1]));
@@ -42,16 +43,24 @@ public ControllersResourceWriter add(String controllerClassName, String customRe
4243
}
4344

4445
public void flush() {
46+
PrintWriter printWriter = null;
4547
try {
4648
final var resource = processingEnvironment
4749
.getFiler()
4850
.createResource(StandardLocation.CLASS_OUTPUT, "", CONTROLLERS_RESOURCE_PATH);
49-
final var printWriter = new PrintWriter(resource.openOutputStream());
51+
printWriter = new PrintWriter(resource.openOutputStream());
52+
53+
5054
for (Map.Entry<String, String> entry : mappings.entrySet()) {
5155
printWriter.println(entry.getKey() + "," + entry.getValue());
5256
}
5357
} catch (IOException e) {
58+
e.printStackTrace();
5459
throw new RuntimeException(e);
60+
} finally {
61+
if (printWriter != null) {
62+
printWriter.close();
63+
}
5564
}
5665
}
5766
}

0 commit comments

Comments
 (0)