Convert to try-with-resources

This commit is contained in:
Jano Svitok 2018-08-06 13:22:55 +02:00
parent bdbb454acb
commit adb0cca09a
2 changed files with 4 additions and 11 deletions

View File

@ -111,13 +111,9 @@ public class RealDeviceTestCases {
@Test
public void testScreenshot() throws Exception {
JadbDevice any = jadb.getAnyDevice();
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(temporaryFolder.newFile("screenshot.png"));
try (FileOutputStream outputStream = new FileOutputStream(temporaryFolder.newFile("screenshot.png"))) {
InputStream stdout = any.executeShell("screencap", "-p");
Stream.copy(stdout, outputStream);
} finally {
if (outputStream != null) outputStream.close();
}
}

View File

@ -12,12 +12,9 @@ public class AdbOutputStreamFixture {
private byte[] passthrough(byte[] input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
OutputStream sut = new AdbFilterOutputStream(output);
try {
sut.write(input);
sut.flush();
} finally {
sut.close();
try (OutputStream sut = new AdbFilterOutputStream(output)) {
sut.write(input);
sut.flush();
}
return output.toByteArray();
}