I have a big problem during one of my unit tests in Java. I compare a byte array with an InputStream and I do not get the same result.
The example is below.
public final class ByteGetInputStreamExampleProblem
{
public static void main( final String[] args ) throws Exception
{
final SecureRandom s = new SecureRandom() ;
final ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
long bPut = 0 ;
final byte[] buffer = new byte[ 2 ] ;
while( bPut < 10 )
{
s.nextBytes( buffer ) ;
bos.write( buffer ) ;
bPut += buffer.length ;
}
final InputStream is = new ByteArrayInputStream( bos.toByteArray() ) ;
System.out.print("A = ");
for( int i = 0 ; i < bos.size() ; i++ )
System.out.print( bos.toByteArray()[i] + ";" ) ;
System.out.print("\nB = ");
int c ;
while( ( c = is.read() ) != -1 )
System.out.print(c + ":");
} ;
} ;
Output:
A = -3;-47;-121;37;-73;83;109;-54;20;106;
B = 253:209:135:37:183:83:109:202:20:106: