@ -69,9 +69,7 @@ public class UnionInputStreamTest {
@Test
public void testReadSingleBytes ( ) throws IOException {
@SuppressWarnings ( "resource" /* java 7 */ )
final UnionInputStream u = new UnionInputStream ( ) ;
try ( UnionInputStream u = new UnionInputStream ( ) ) {
assertTrue ( u . isEmpty ( ) ) ;
u . add ( new ByteArrayInputStream ( new byte [ ] { 1 , 0 , 2 } ) ) ;
u . add ( new ByteArrayInputStream ( new byte [ ] { 3 } ) ) ;
@ -99,11 +97,11 @@ public class UnionInputStreamTest {
assertEquals ( - 1 , u . read ( ) ) ;
assertTrue ( u . isEmpty ( ) ) ;
}
}
@Test
public void testReadByteBlocks ( ) throws IOException {
@SuppressWarnings ( "resource" /* java 7 */ )
final UnionInputStream u = new UnionInputStream ( ) ;
try ( UnionInputStream u = new UnionInputStream ( ) ) {
u . add ( new ByteArrayInputStream ( new byte [ ] { 1 , 0 , 2 } ) ) ;
u . add ( new ByteArrayInputStream ( new byte [ ] { 3 } ) ) ;
u . add ( new ByteArrayInputStream ( new byte [ ] { 4 , 5 } ) ) ;
@ -117,6 +115,7 @@ public class UnionInputStreamTest {
assertTrue ( Arrays . equals ( new byte [ ] { 4 , 5 , } , slice ( r , 2 ) ) ) ;
assertEquals ( - 1 , u . read ( r , 0 , 5 ) ) ;
}
}
private static byte [ ] slice ( byte [ ] in , int len ) {
byte [ ] r = new byte [ len ] ;
@ -126,12 +125,10 @@ public class UnionInputStreamTest {
@Test
public void testArrayConstructor ( ) throws IOException {
@SuppressWarnings ( "resource" /* java 7 */ )
final UnionInputStream u = new UnionInputStream (
try ( UnionInputStream u = new UnionInputStream (
new ByteArrayInputStream ( new byte [ ] { 1 , 0 , 2 } ) ,
new ByteArrayInputStream ( new byte [ ] { 3 } ) ,
new ByteArrayInputStream ( new byte [ ] { 4 , 5 } ) ) ;
new ByteArrayInputStream ( new byte [ ] { 4 , 5 } ) ) ) {
final byte [ ] r = new byte [ 5 ] ;
assertEquals ( 3 , u . read ( r , 0 , 5 ) ) ;
assertTrue ( Arrays . equals ( new byte [ ] { 1 , 0 , 2 , } , slice ( r , 3 ) ) ) ;
@ -141,20 +138,20 @@ public class UnionInputStreamTest {
assertTrue ( Arrays . equals ( new byte [ ] { 4 , 5 , } , slice ( r , 2 ) ) ) ;
assertEquals ( - 1 , u . read ( r , 0 , 5 ) ) ;
}
}
@Test
public void testMarkSupported ( ) {
@SuppressWarnings ( "resource" /* java 7 */ )
final UnionInputStream u = new UnionInputStream ( ) ;
public void testMarkSupported ( ) throws IOException {
try ( UnionInputStream u = new UnionInputStream ( ) ) {
assertFalse ( u . markSupported ( ) ) ;
u . add ( new ByteArrayInputStream ( new byte [ ] { 1 , 0 , 2 } ) ) ;
assertFalse ( u . markSupported ( ) ) ;
}
}
@Test
public void testSkip ( ) throws IOException {
@SuppressWarnings ( "resource" /* java 7 */ )
final UnionInputStream u = new UnionInputStream ( ) ;
try ( UnionInputStream u = new UnionInputStream ( ) ) {
u . add ( new ByteArrayInputStream ( new byte [ ] { 1 , 0 , 2 } ) ) ;
u . add ( new ByteArrayInputStream ( new byte [ ] { 3 } ) ) ;
u . add ( new ByteArrayInputStream ( new byte [ ] { 4 , 5 } ) ) ;
@ -176,11 +173,11 @@ public class UnionInputStreamTest {
assertEquals ( 2 , u . skip ( 8 ) ) ;
assertEquals ( - 1 , u . read ( ) ) ;
}
}
@Test
public void testAutoCloseDuringRead ( ) throws IOException {
@SuppressWarnings ( "resource" /* java 7 */ )
final UnionInputStream u = new UnionInputStream ( ) ;
try ( UnionInputStream u = new UnionInputStream ( ) ) {
final boolean closed [ ] = new boolean [ 2 ] ;
u . add ( new ByteArrayInputStream ( new byte [ ] { 1 } ) {
@Override
@ -210,6 +207,7 @@ public class UnionInputStreamTest {
assertTrue ( closed [ 0 ] ) ;
assertTrue ( closed [ 1 ] ) ;
}
}
@Test
public void testCloseDuringClose ( ) throws IOException {
@ -267,13 +265,12 @@ public class UnionInputStreamTest {
throw new IOException ( "Expected" ) ;
}
} ;
@SuppressWarnings ( "resource" /* java 7 */ )
final UnionInputStream u = new UnionInputStream (
new ByteArrayInputStream ( new byte [ ] { 1 , 2 , 3 } ) ,
errorReadStream ) ;
try ( UnionInputStream u = new UnionInputStream (
new ByteArrayInputStream ( new byte [ ] { 1 , 2 , 3 } ) ,
errorReadStream ) ) {
byte buf [ ] = new byte [ 10 ] ;
assertEquals ( 3 , u . read ( buf , 0 , 10 ) ) ;
assertTrue ( Arrays . equals ( new byte [ ] { 1 , 2 , 3 } , slice ( buf , 3 ) ) ) ;
assertTrue ( Arrays . equals ( new byte [ ] { 1 , 2 , 3 } , slice ( buf , 3 ) ) ) ;
try {
u . read ( buf , 0 , 1 ) ;
fail ( "Expected exception from errorReadStream" ) ;
@ -281,4 +278,5 @@ public class UnionInputStreamTest {
assertEquals ( "Expected" , e . getMessage ( ) ) ;
}
}
}
}