@@ -105,6 +105,7 @@ public void testCodec101() throws Exception {
105105
106106 c = in .read (result );
107107 assertTrue ("Codec101: Second read should report end-of-stream [c=" + c + "]" , c < 0 );
108+ in .close ();
108109 }
109110
110111 /**
@@ -131,6 +132,7 @@ public void testInputStreamReader() throws Exception {
131132 BufferedReader br = new BufferedReader (isr );
132133 String line = br .readLine ();
133134 assertNotNull ("Codec101: InputStreamReader works!" , line );
135+ br .close ();
134136 }
135137
136138 /**
@@ -168,6 +170,7 @@ public void testAvailable() throws Throwable {
168170 assertEquals (-1 , b64stream .read ());
169171 assertEquals (-1 , b64stream .read ());
170172 assertEquals (0 , b64stream .available ());
173+ b64stream .close ();
171174 }
172175
173176 /**
@@ -296,17 +299,18 @@ public void testBase64InputStreamByteByByte() throws Exception {
296299 private void testByChunk (byte [] encoded , byte [] decoded , int chunkSize , byte [] seperator ) throws Exception {
297300
298301 // Start with encode.
299- InputStream in = new ByteArrayInputStream ( decoded ) ;
300- in = new Base64InputStream (in , true , chunkSize , seperator );
302+ InputStream in ;
303+ in = new Base64InputStream (new ByteArrayInputStream ( decoded ) , true , chunkSize , seperator );
301304 byte [] output = Base64TestData .streamToBytes (in );
302305
303306 assertEquals ("EOF" , -1 , in .read ());
304307 assertEquals ("Still EOF" , -1 , in .read ());
305308 assertTrue ("Streaming base64 encode" , Arrays .equals (output , encoded ));
306309
310+ in .close ();
311+
307312 // Now let's try decode.
308- in = new ByteArrayInputStream (encoded );
309- in = new Base64InputStream (in );
313+ in = new Base64InputStream (new ByteArrayInputStream (encoded ));
310314 output = Base64TestData .streamToBytes (in );
311315
312316 assertEquals ("EOF" , -1 , in .read ());
@@ -324,6 +328,7 @@ private void testByChunk(byte[] encoded, byte[] decoded, int chunkSize, byte[] s
324328 assertEquals ("EOF" , -1 , in .read ());
325329 assertEquals ("Still EOF" , -1 , in .read ());
326330 assertTrue ("Streaming base64 wrap-wrap-wrap!" , Arrays .equals (output , decoded ));
331+ in .close ();
327332 }
328333
329334 /**
@@ -347,8 +352,8 @@ private void testByChunk(byte[] encoded, byte[] decoded, int chunkSize, byte[] s
347352 private void testByteByByte (byte [] encoded , byte [] decoded , int chunkSize , byte [] seperator ) throws Exception {
348353
349354 // Start with encode.
350- InputStream in = new ByteArrayInputStream ( decoded ) ;
351- in = new Base64InputStream (in , true , chunkSize , seperator );
355+ InputStream in ;
356+ in = new Base64InputStream (new ByteArrayInputStream ( decoded ) , true , chunkSize , seperator );
352357 byte [] output = new byte [encoded .length ];
353358 for (int i = 0 ; i < output .length ; i ++) {
354359 output [i ] = (byte ) in .read ();
@@ -358,9 +363,9 @@ private void testByteByByte(byte[] encoded, byte[] decoded, int chunkSize, byte[
358363 assertEquals ("Still EOF" , -1 , in .read ());
359364 assertTrue ("Streaming base64 encode" , Arrays .equals (output , encoded ));
360365
366+ in .close ();
361367 // Now let's try decode.
362- in = new ByteArrayInputStream (encoded );
363- in = new Base64InputStream (in );
368+ in = new Base64InputStream (new ByteArrayInputStream (encoded ));
364369 output = new byte [decoded .length ];
365370 for (int i = 0 ; i < output .length ; i ++) {
366371 output [i ] = (byte ) in .read ();
@@ -370,6 +375,8 @@ private void testByteByByte(byte[] encoded, byte[] decoded, int chunkSize, byte[
370375 assertEquals ("Still EOF" , -1 , in .read ());
371376 assertTrue ("Streaming base64 decode" , Arrays .equals (output , decoded ));
372377
378+ in .close ();
379+
373380 // I always wanted to do this! (wrap encoder with decoder etc etc).
374381 in = new ByteArrayInputStream (decoded );
375382 for (int i = 0 ; i < 10 ; i ++) {
@@ -384,6 +391,7 @@ private void testByteByByte(byte[] encoded, byte[] decoded, int chunkSize, byte[
384391 assertEquals ("EOF" , -1 , in .read ());
385392 assertEquals ("Still EOF" , -1 , in .read ());
386393 assertTrue ("Streaming base64 wrap-wrap-wrap!" , Arrays .equals (output , decoded ));
394+ in .close ();
387395 }
388396
389397 /**
@@ -398,6 +406,7 @@ public void testMarkSupported() throws Exception {
398406 Base64InputStream in = new Base64InputStream (bin , true , 4 , new byte [] { 0 , 0 , 0 });
399407 // Always returns false for now.
400408 assertFalse ("Base64InputStream.markSupported() is false" , in .markSupported ());
409+ in .close ();
401410 }
402411
403412 /**
@@ -414,6 +423,7 @@ public void testRead0() throws Exception {
414423 Base64InputStream in = new Base64InputStream (bin , true , 4 , new byte [] { 0 , 0 , 0 });
415424 bytesRead = in .read (buf , 0 , 0 );
416425 assertEquals ("Base64InputStream.read(buf, 0, 0) returns 0" , 0 , bytesRead );
426+ in .close ();
417427 }
418428
419429 /**
@@ -433,6 +443,7 @@ public void testReadNull() throws Exception {
433443 } catch (NullPointerException e ) {
434444 // Expected
435445 }
446+ in .close ();
436447 }
437448
438449 /**
@@ -474,6 +485,7 @@ public void testReadOutOfBounds() throws Exception {
474485 } catch (IndexOutOfBoundsException e ) {
475486 // Expected
476487 }
488+ in .close ();
477489 }
478490
479491 /**
@@ -489,6 +501,7 @@ public void testSkipBig() throws Throwable {
489501 // End of stream reached
490502 assertEquals (-1 , b64stream .read ());
491503 assertEquals (-1 , b64stream .read ());
504+ b64stream .close ();
492505 }
493506
494507 /**
@@ -506,6 +519,7 @@ public void testSkipNone() throws Throwable {
506519 assertArrayEquals (actualBytes , new byte [] { 0 , 0 , 0 , (byte ) 255 , (byte ) 255 , (byte ) 255 });
507520 // End of stream reached
508521 assertEquals (-1 , b64stream .read ());
522+ b64stream .close ();
509523 }
510524
511525 /**
@@ -522,6 +536,7 @@ public void testSkipPastEnd() throws Throwable {
522536 // End of stream reached
523537 assertEquals (-1 , b64stream .read ());
524538 assertEquals (-1 , b64stream .read ());
539+ b64stream .close ();
525540 }
526541
527542 /**
@@ -538,6 +553,7 @@ public void testSkipToEnd() throws Throwable {
538553 // End of stream reached
539554 assertEquals (-1 , b64stream .read ());
540555 assertEquals (-1 , b64stream .read ());
556+ b64stream .close ();
541557 }
542558
543559 /**
@@ -550,5 +566,6 @@ public void testSkipWrongArgument() throws Throwable {
550566 InputStream ins = new ByteArrayInputStream (StringUtils .getBytesIso8859_1 (ENCODED_B64 ));
551567 Base64InputStream b64stream = new Base64InputStream (ins );
552568 b64stream .skip (-10 );
569+ b64stream .close ();
553570 }
554571}
0 commit comments