public static void assertEqualStreams(InputStream expIn,InputStream actIn,@Nullable Long expSize) throws IOException {
  int bufSize=2345;
  byte buf1[]=new byte[bufSize];
  byte buf2[]=new byte[bufSize];
  long pos=0;
  while (true) {
    int i1=actIn.read(buf1,0,bufSize);
    int i2;
    if (i1 == -1)     i2=expIn.read(buf2,0,1);
 else     IOUtils.readFully(expIn,buf2,0,i2=i1);
    if (i1 != i2)     fail("Expects the same data [pos=" + pos + ", i1="+ i1+ ", i2="+ i2+ ']');
    if (i1 == -1)     break;
    assertTrue("Expects the same data [pos=" + pos + ", i1="+ i1+ ", i2="+ i2+ ']',Arrays.equals(buf1,buf2));
    pos+=i1;
  }
  if (expSize != null)   assertEquals(expSize.longValue(),pos);
}

public static void assertEqualStreams ( InputStream expIn , InputStream actIn , @ Nullable Long expSize ) throws IOException { int bufSize = 2345 ; byte buf1 [ ] = new byte [ bufSize ] ; byte buf2 [ ] = new byte [ bufSize ] ; long pos = 0 ; while ( true ) { int i1 = actIn . read ( buf1 , 0 , bufSize ) ; int i2 ; if ( i1 == - 1 ) i2 = expIn . read ( buf2 , 0 , 1 ) ; else IOUtils . readFully ( expIn , buf2 , 0 , i2 = i1 ) ; if ( i1 != i2 ) fail ( "Expects the same data [pos=" + pos + ", i1=" + i1 + ", i2=" + i2 + ']' ) ; if ( i1 == - 1 ) break ; assertTrue ( "Expects the same data [pos=" + pos + ", i1=" + i1 + ", i2=" + i2 + ']' , Arrays . equals ( buf1 , buf2 ) ) ; pos += i1 ; } if ( expSize != null ) assertEquals ( expSize . longValue ( ) , pos ) ; }
validate streams generate the same output .
