[java] Refactoring OutputType.FILE#save
Leveraging Java 7 Files class.
package org.openqa.selenium;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Base64;
/**
@@ -85,18 +85,14 @@ public File convertFromPngBytes(byte[] data) {
private File save(byte[] data) {
try {
- File tmpFile = File.createTempFile("screenshot", ".png");
+ Path tmpFilePath = Files.createTempFile("screenshot", ".png");
+ File tmpFile = tmpFilePath.toFile();
tmpFile.deleteOnExit();
-
- try (OutputStream stream = new FileOutputStream(tmpFile)) {
- stream.write(data);
+ Files.write(tmpFilePath, data);
return tmpFile;
} catch (IOException e) {
throw new WebDriverException(e);
}
- } catch (IOException e) {
- throw new WebDriverException(e);
- }
}
public String toString() {
