Skip to content

Commit cf3f36a

Browse files
authored
[java] Refactoring OutputType.FILE#save (#9309)
Leveraging Java 7 Files class.
1 parent 0849604 commit cf3f36a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
package org.openqa.selenium;
1919

2020
import java.io.File;
21-
import java.io.FileOutputStream;
2221
import java.io.IOException;
23-
import java.io.OutputStream;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
2424
import java.util.Base64;
2525

2626
/**
@@ -85,15 +85,11 @@ public File convertFromPngBytes(byte[] data) {
8585

8686
private File save(byte[] data) {
8787
try {
88-
File tmpFile = File.createTempFile("screenshot", ".png");
88+
Path tmpFilePath = Files.createTempFile("screenshot", ".png");
89+
File tmpFile = tmpFilePath.toFile();
8990
tmpFile.deleteOnExit();
90-
91-
try (OutputStream stream = new FileOutputStream(tmpFile)) {
92-
stream.write(data);
93-
return tmpFile;
94-
} catch (IOException e) {
95-
throw new WebDriverException(e);
96-
}
91+
Files.write(tmpFilePath, data);
92+
return tmpFile;
9793
} catch (IOException e) {
9894
throw new WebDriverException(e);
9995
}

0 commit comments

Comments
 (0)