Exemplo n.º 1
0
 @Test(expected = EOFException.class)
 public void testReadFully_throws_exception_if_not_enough_data() throws IOException {
   InputStream inputStream = new ByteArrayInputStream(new byte[0]);
   DataIO.readFully(inputStream, new byte[1]);
   fail(
       "An EOFException should have occurred by now since there are not enough bytes to read from the InputStream");
 }
Exemplo n.º 2
0
 @Test
 public void testReadFully_with_data_length_same_as_buffer_length() throws IOException {
   byte[] inputBuffer = new byte[] {1, 2, 3, 4};
   InputStream in = new ByteArrayInputStream(inputBuffer);
   byte[] outputBuffer = new byte[4];
   DataIO.readFully(in, outputBuffer);
   assertArrayEquals(
       "The passed buffer should be filled with the whole content of the InputStream"
           + " since the buffer length is exactly same as the data length",
       inputBuffer,
       outputBuffer);
 }
Exemplo n.º 3
0
 @Test
 public void testReadFully_with_too_much_data() throws IOException {
   byte[] inputBuffer = new byte[] {1, 2, 3, 4};
   InputStream in = new ByteArrayInputStream(inputBuffer);
   byte[] outputBuffer = new byte[3];
   DataIO.readFully(in, outputBuffer);
   byte[] expected = new byte[] {1, 2, 3};
   assertArrayEquals(
       "The passed buffer should be filled with the first three bytes read from the InputStream",
       expected,
       outputBuffer);
 }