commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1379025 - in /commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary: Base32InputStreamTest.java Base64InputStreamTest.java
Date Thu, 30 Aug 2012 17:21:38 GMT
Author: sebb
Date: Thu Aug 30 17:21:37 2012
New Revision: 1379025

URL: http://svn.apache.org/viewvc?rev=1379025&view=rev
Log:
Eclipse warns that files are not closed

Modified:
    commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
    commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java

Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java?rev=1379025&r1=1379024&r2=1379025&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
(original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
Thu Aug 30 17:21:37 2012
@@ -160,6 +160,7 @@ public class Base32InputStreamTest {
         assertEquals(-1, b32stream.read());
         assertEquals(-1, b32stream.read());
         assertEquals(0, b32stream.available());
+        b32stream.close();
     }
 
     /**
@@ -285,8 +286,9 @@ public class Base32InputStreamTest {
     private void testByChunk(byte[] encoded, byte[] decoded, int chunkSize, byte[] seperator)
throws Exception {
 
         // Start with encode.
-        InputStream in = new ByteArrayInputStream(decoded);
-        in = new Base32InputStream(in, true, chunkSize, seperator);
+        InputStream in;
+        
+        in = new Base32InputStream(new ByteArrayInputStream(decoded), true, chunkSize, seperator);
         byte[] output = Base32TestData.streamToBytes(in);
 
         assertEquals("EOF", -1, in.read());
@@ -294,8 +296,7 @@ public class Base32InputStreamTest {
         assertTrue("Streaming base32 encode", Arrays.equals(output, encoded));
 
         // Now let's try decode.
-        in = new ByteArrayInputStream(encoded);
-        in = new Base32InputStream(in);
+        in = new Base32InputStream(new ByteArrayInputStream(encoded));
         output = Base32TestData.streamToBytes(in);
 
         assertEquals("EOF", -1, in.read());
@@ -313,6 +314,7 @@ public class Base32InputStreamTest {
         assertEquals("EOF", -1, in.read());
         assertEquals("Still EOF", -1, in.read());
         assertTrue("Streaming base32 wrap-wrap-wrap!", Arrays.equals(output, decoded));
+        in.close();
     }
 
     /**
@@ -336,8 +338,8 @@ public class Base32InputStreamTest {
     private void testByteByByte(byte[] encoded, byte[] decoded, int chunkSize, byte[] seperator)
throws Exception {
 
         // Start with encode.
-        InputStream in = new ByteArrayInputStream(decoded);
-        in = new Base32InputStream(in, true, chunkSize, seperator);
+        InputStream in;
+        in = new Base32InputStream(new ByteArrayInputStream(decoded), true, chunkSize, seperator);
         byte[] output = new byte[encoded.length];
         for (int i = 0; i < output.length; i++) {
             output[i] = (byte) in.read();
@@ -347,9 +349,10 @@ public class Base32InputStreamTest {
         assertEquals("Still EOF", -1, in.read());
         assertTrue("Streaming base32 encode", Arrays.equals(output, encoded));
 
+        in.close();
+
         // Now let's try decode.
-        in = new ByteArrayInputStream(encoded);
-        in = new Base32InputStream(in);
+        in = new Base32InputStream(new ByteArrayInputStream(encoded));
         output = new byte[decoded.length];
         for (int i = 0; i < output.length; i++) {
             output[i] = (byte) in.read();
@@ -359,6 +362,8 @@ public class Base32InputStreamTest {
         assertEquals("Still EOF", -1, in.read());
         assertTrue("Streaming base32 decode", Arrays.equals(output, decoded));
 
+        in.close();
+ 
         // I always wanted to do this! (wrap encoder with decoder etc etc).
         in = new ByteArrayInputStream(decoded);
         for (int i = 0; i < 10; i++) {
@@ -387,6 +392,7 @@ public class Base32InputStreamTest {
         Base32InputStream in = new Base32InputStream(bin, true, 4, new byte[] { 0, 0, 0 });
         // Always returns false for now.
         assertFalse("Base32InputStream.markSupported() is false", in.markSupported());
+        in.close();
     }
 
     /**
@@ -403,6 +409,7 @@ public class Base32InputStreamTest {
         Base32InputStream in = new Base32InputStream(bin, true, 4, new byte[] { 0, 0, 0 });
         bytesRead = in.read(buf, 0, 0);
         assertEquals("Base32InputStream.read(buf, 0, 0) returns 0", 0, bytesRead);
+        in.close();
     }
 
     /**
@@ -422,6 +429,7 @@ public class Base32InputStreamTest {
         } catch (NullPointerException e) {
             // Expected
         }
+        in.close();
     }
 
     /**
@@ -463,6 +471,7 @@ public class Base32InputStreamTest {
         } catch (IndexOutOfBoundsException e) {
             // Expected
         }
+        in.close();
     }
 
     /**
@@ -480,6 +489,7 @@ public class Base32InputStreamTest {
         assertArrayEquals(actualBytes, new byte[] { 102, 111, 111, 0, 0, 0 });
         // End of stream reached
         assertEquals(-1, b32stream.read());
+        b32stream.close();
     }
 
     /**
@@ -495,6 +505,7 @@ public class Base32InputStreamTest {
         // End of stream reached
         assertEquals(-1, b32stream.read());
         assertEquals(-1, b32stream.read());
+        b32stream.close();
     }
 
     /**
@@ -511,7 +522,8 @@ public class Base32InputStreamTest {
         // End of stream reached
         assertEquals(-1, b32stream.read());
         assertEquals(-1, b32stream.read());
-    }
+        b32stream.close();
+}
 
     /**
      * Tests skipping to the end of a stream.
@@ -527,6 +539,7 @@ public class Base32InputStreamTest {
         // End of stream reached
         assertEquals(-1, b32stream.read());
         assertEquals(-1, b32stream.read());
+        b32stream.close();
     }
 
     /**
@@ -539,5 +552,6 @@ public class Base32InputStreamTest {
         InputStream ins = new ByteArrayInputStream(StringUtils.getBytesIso8859_1(ENCODED_FOO));
         Base32InputStream b32stream = new Base32InputStream(ins);
         b32stream.skip(-10);
+        b32stream.close();
     }
 }

Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java?rev=1379025&r1=1379024&r2=1379025&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
(original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
Thu Aug 30 17:21:37 2012
@@ -105,6 +105,7 @@ public class Base64InputStreamTest {
 
         c = in.read(result);
         assertTrue("Codec101: Second read should report end-of-stream [c=" + c + "]", c <
0);
+        in.close();
     }
 
     /**
@@ -131,6 +132,7 @@ public class Base64InputStreamTest {
         BufferedReader br = new BufferedReader(isr);
         String line = br.readLine();
         assertNotNull("Codec101:  InputStreamReader works!", line);
+        br.close();
     }
 
     /**
@@ -168,6 +170,7 @@ public class Base64InputStreamTest {
         assertEquals(-1, b64stream.read());
         assertEquals(-1, b64stream.read());
         assertEquals(0, b64stream.available());
+        b64stream.close();
     }
 
     /**
@@ -296,17 +299,18 @@ public class Base64InputStreamTest {
     private void testByChunk(byte[] encoded, byte[] decoded, int chunkSize, byte[] seperator)
throws Exception {
 
         // Start with encode.
-        InputStream in = new ByteArrayInputStream(decoded);
-        in = new Base64InputStream(in, true, chunkSize, seperator);
+        InputStream in;
+        in = new Base64InputStream(new ByteArrayInputStream(decoded), true, chunkSize, seperator);
         byte[] output = Base64TestData.streamToBytes(in);
 
         assertEquals("EOF", -1, in.read());
         assertEquals("Still EOF", -1, in.read());
         assertTrue("Streaming base64 encode", Arrays.equals(output, encoded));
 
+        in.close();
+        
         // Now let's try decode.
-        in = new ByteArrayInputStream(encoded);
-        in = new Base64InputStream(in);
+        in = new Base64InputStream(new ByteArrayInputStream(encoded));
         output = Base64TestData.streamToBytes(in);
 
         assertEquals("EOF", -1, in.read());
@@ -324,6 +328,7 @@ public class Base64InputStreamTest {
         assertEquals("EOF", -1, in.read());
         assertEquals("Still EOF", -1, in.read());
         assertTrue("Streaming base64 wrap-wrap-wrap!", Arrays.equals(output, decoded));
+        in.close();
     }
 
     /**
@@ -347,8 +352,8 @@ public class Base64InputStreamTest {
     private void testByteByByte(byte[] encoded, byte[] decoded, int chunkSize, byte[] seperator)
throws Exception {
 
         // Start with encode.
-        InputStream in = new ByteArrayInputStream(decoded);
-        in = new Base64InputStream(in, true, chunkSize, seperator);
+        InputStream in;
+        in = new Base64InputStream(new ByteArrayInputStream(decoded), true, chunkSize, seperator);
         byte[] output = new byte[encoded.length];
         for (int i = 0; i < output.length; i++) {
             output[i] = (byte) in.read();
@@ -358,9 +363,9 @@ public class Base64InputStreamTest {
         assertEquals("Still EOF", -1, in.read());
         assertTrue("Streaming base64 encode", Arrays.equals(output, encoded));
 
+        in.close();
         // Now let's try decode.
-        in = new ByteArrayInputStream(encoded);
-        in = new Base64InputStream(in);
+        in = new Base64InputStream(new ByteArrayInputStream(encoded));
         output = new byte[decoded.length];
         for (int i = 0; i < output.length; i++) {
             output[i] = (byte) in.read();
@@ -370,6 +375,8 @@ public class Base64InputStreamTest {
         assertEquals("Still EOF", -1, in.read());
         assertTrue("Streaming base64 decode", Arrays.equals(output, decoded));
 
+        in.close();
+        
         // I always wanted to do this! (wrap encoder with decoder etc etc).
         in = new ByteArrayInputStream(decoded);
         for (int i = 0; i < 10; i++) {
@@ -384,6 +391,7 @@ public class Base64InputStreamTest {
         assertEquals("EOF", -1, in.read());
         assertEquals("Still EOF", -1, in.read());
         assertTrue("Streaming base64 wrap-wrap-wrap!", Arrays.equals(output, decoded));
+        in.close();
     }
 
     /**
@@ -398,6 +406,7 @@ public class Base64InputStreamTest {
         Base64InputStream in = new Base64InputStream(bin, true, 4, new byte[] { 0, 0, 0 });
         // Always returns false for now.
         assertFalse("Base64InputStream.markSupported() is false", in.markSupported());
+        in.close();
     }
 
     /**
@@ -414,6 +423,7 @@ public class Base64InputStreamTest {
         Base64InputStream in = new Base64InputStream(bin, true, 4, new byte[] { 0, 0, 0 });
         bytesRead = in.read(buf, 0, 0);
         assertEquals("Base64InputStream.read(buf, 0, 0) returns 0", 0, bytesRead);
+        in.close();
     }
 
     /**
@@ -433,6 +443,7 @@ public class Base64InputStreamTest {
         } catch (NullPointerException e) {
             // Expected
         }
+        in.close();
     }
 
     /**
@@ -474,6 +485,7 @@ public class Base64InputStreamTest {
         } catch (IndexOutOfBoundsException e) {
             // Expected
         }
+        in.close();
     }
 
     /**
@@ -489,6 +501,7 @@ public class Base64InputStreamTest {
         // End of stream reached
         assertEquals(-1, b64stream.read());
         assertEquals(-1, b64stream.read());
+        b64stream.close();
     }
 
     /**
@@ -506,6 +519,7 @@ public class Base64InputStreamTest {
         assertArrayEquals(actualBytes, new byte[] { 0, 0, 0, (byte) 255, (byte) 255, (byte)
255 });
         // End of stream reached
         assertEquals(-1, b64stream.read());
+        b64stream.close();
     }
 
     /**
@@ -522,6 +536,7 @@ public class Base64InputStreamTest {
         // End of stream reached
         assertEquals(-1, b64stream.read());
         assertEquals(-1, b64stream.read());
+        b64stream.close();
     }
 
     /**
@@ -538,6 +553,7 @@ public class Base64InputStreamTest {
         // End of stream reached
         assertEquals(-1, b64stream.read());
         assertEquals(-1, b64stream.read());
+        b64stream.close();
     }
 
     /**
@@ -550,5 +566,6 @@ public class Base64InputStreamTest {
         InputStream ins = new ByteArrayInputStream(StringUtils.getBytesIso8859_1(ENCODED_B64));
         Base64InputStream b64stream = new Base64InputStream(ins);
         b64stream.skip(-10);
+        b64stream.close();
     }
 }



Mime
View raw message