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 @Test
public void testScreenshot() throws Exception { public void testScreenshot() throws Exception {
JadbDevice any = jadb.getAnyDevice(); JadbDevice any = jadb.getAnyDevice();
FileOutputStream outputStream = null; try (FileOutputStream outputStream = new FileOutputStream(temporaryFolder.newFile("screenshot.png"))) {
try {
outputStream = new FileOutputStream(temporaryFolder.newFile("screenshot.png"));
InputStream stdout = any.executeShell("screencap", "-p"); InputStream stdout = any.executeShell("screencap", "-p");
Stream.copy(stdout, outputStream); 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 { private byte[] passthrough(byte[] input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream(); ByteArrayOutputStream output = new ByteArrayOutputStream();
OutputStream sut = new AdbFilterOutputStream(output); try (OutputStream sut = new AdbFilterOutputStream(output)) {
try {
sut.write(input); sut.write(input);
sut.flush(); sut.flush();
} finally {
sut.close();
} }
return output.toByteArray(); return output.toByteArray();
} }