[java] Using try-with-resources to simplify code
@@ -84,26 +84,18 @@ public File convertFromPngBytes(byte[] data) {
}
private File save(byte[] data) {
- OutputStream stream = null;
-
try {
File tmpFile = File.createTempFile("screenshot", ".png");
tmpFile.deleteOnExit();
- stream = new FileOutputStream(tmpFile);
+ try (OutputStream stream = new FileOutputStream(tmpFile)) {
stream.write(data);
-
return tmpFile;
} catch (IOException e) {
throw new WebDriverException(e);
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- // Nothing sane to do
- }
}
+ } catch (IOException e) {
+ throw new WebDriverException(e);
}
}
