Repository: commons-compress
Updated Branches:
  refs/heads/master e71827b5d -> 7ee18aa0c


Use try with resources.

Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/7ee18aa0
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/7ee18aa0
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/7ee18aa0

Branch: refs/heads/master
Commit: 7ee18aa0cc99a429e6ff9e3fe4b5e73f91b99776
Parents: e71827b
Author: Gary Gregory <ggreg...@apache.org>
Authored: Mon Sep 5 15:40:10 2016 -0400
Committer: Gary Gregory <ggreg...@apache.org>
Committed: Mon Sep 5 15:40:10 2016 -0400

----------------------------------------------------------------------
 .../compress/utils/CountingStreamTest.java      | 56 ++++++++++----------
 1 file changed, 28 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/7ee18aa0/src/test/java/org/apache/commons/compress/utils/CountingStreamTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/compress/utils/CountingStreamTest.java 
b/src/test/java/org/apache/commons/compress/utils/CountingStreamTest.java
index 70e70b7..3be1870 100644
--- a/src/test/java/org/apache/commons/compress/utils/CountingStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/utils/CountingStreamTest.java
@@ -33,18 +33,18 @@ public class CountingStreamTest {
         // I don't like "test all at once" tests either, but the class
         // is so trivial
         final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        final CountingOutputStream o = new CountingOutputStream(bos);
-        o.write(1);
-        assertEquals(1, o.getBytesWritten());
-        o.write(new byte[] { 2, 3 });
-        assertEquals(3, o.getBytesWritten());
-        o.write(new byte[] { 2, 3, 4, 5, }, 2, 1);
-        assertEquals(4, o.getBytesWritten());
-        o.count(-1);
-        assertEquals(4, o.getBytesWritten());
-        o.count(-2);
-        assertEquals(2, o.getBytesWritten());
-        o.close();
+        try (final CountingOutputStream o = new CountingOutputStream(bos)) {
+            o.write(1);
+            assertEquals(1, o.getBytesWritten());
+            o.write(new byte[] { 2, 3 });
+            assertEquals(3, o.getBytesWritten());
+            o.write(new byte[] { 2, 3, 4, 5, }, 2, 1);
+            assertEquals(4, o.getBytesWritten());
+            o.count(-1);
+            assertEquals(4, o.getBytesWritten());
+            o.count(-2);
+            assertEquals(2, o.getBytesWritten());
+        }
         assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bos.toByteArray());
     }
 
@@ -54,22 +54,22 @@ public class CountingStreamTest {
         // is so trivial
         final ByteArrayInputStream bis =
             new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 });
-        final CountingInputStream i = new CountingInputStream(bis);
-        assertEquals(1, i.read());
-        assertEquals(1, i.getBytesRead());
-        byte[] b = new byte[2];
-        i.read(b);
-        assertEquals(3, i.getBytesRead());
-        assertArrayEquals(new byte[] { 2, 3 }, b);
-        b = new byte[3];
-        i.read(b, 1, 1);
-        assertArrayEquals(new byte[] { 0, 4, 0 }, b);
-        assertEquals(4, i.getBytesRead());
-        i.count(-1);
-        assertEquals(4, i.getBytesRead());
-        i.count(-2);
-        assertEquals(2, i.getBytesRead());
-        i.close();
+        try (final CountingInputStream i = new CountingInputStream(bis)) {
+            assertEquals(1, i.read());
+            assertEquals(1, i.getBytesRead());
+            byte[] b = new byte[2];
+            i.read(b);
+            assertEquals(3, i.getBytesRead());
+            assertArrayEquals(new byte[] { 2, 3 }, b);
+            b = new byte[3];
+            i.read(b, 1, 1);
+            assertArrayEquals(new byte[] { 0, 4, 0 }, b);
+            assertEquals(4, i.getBytesRead());
+            i.count(-1);
+            assertEquals(4, i.getBytesRead());
+            i.count(-2);
+            assertEquals(2, i.getBytesRead());
+        }
     }
 
 }

Reply via email to