Skip to content

Commit 2e8b5a5

Browse files
committed
[java] Using try-with-resources to simplify code
1 parent bd2fc34 commit 2e8b5a5

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

java/client/src/org/openqa/selenium/OutputType.java

+6-14
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,18 @@ public File convertFromPngBytes(byte[] data) {
8484
}
8585

8686
private File save(byte[] data) {
87-
OutputStream stream = null;
88-
8987
try {
9088
File tmpFile = File.createTempFile("screenshot", ".png");
9189
tmpFile.deleteOnExit();
9290

93-
stream = new FileOutputStream(tmpFile);
94-
stream.write(data);
95-
96-
return tmpFile;
91+
try (OutputStream stream = new FileOutputStream(tmpFile)) {
92+
stream.write(data);
93+
return tmpFile;
94+
} catch (IOException e) {
95+
throw new WebDriverException(e);
96+
}
9797
} catch (IOException e) {
9898
throw new WebDriverException(e);
99-
} finally {
100-
if (stream != null) {
101-
try {
102-
stream.close();
103-
} catch (IOException e) {
104-
// Nothing sane to do
105-
}
106-
}
10799
}
108100
}
109101

0 commit comments

Comments
 (0)