### Question:
CrcInputStream extends InputStream { public CrcInputStream(InputStream in) { this(new Crc32(), in); } CrcInputStream(InputStream in);  CrcInputStream(Crc32 crc, InputStream in); @Override int read(); @Override int read(byte[] b); @Override int read(byte[] b, int off, int len); void updateCrc(ByteBuffer buffer); @Override int available(); @Override void close(); long getValue(); InputStream getUnderlyingInputStream();  }### Answer:
@Test public void testCrcInputStream() throws IOException { byte[] buf = new byte[4000]; new Random().nextBytes(buf); ByteBufferInputStream stream = new ByteBufferInputStream(ByteBuffer.wrap(buf)); CrcInputStream crcStream = new CrcInputStream(stream); byte[] bufOutput = new byte[4000]; try { crcStream.read(bufOutput); } catch (IOException e) { Assert.assertTrue(false); } Assert.assertArrayEquals(buf, bufOutput); long value1 = crcStream.getValue(); stream = new ByteBufferInputStream(ByteBuffer.wrap(buf)); crcStream = new CrcInputStream(stream); try { crcStream.read(bufOutput, 0, 3999); bufOutput[3999] = (byte) crcStream.read(); } catch (IOException e) { Assert.assertTrue(false); } Assert.assertArrayEquals(buf, bufOutput); long value2 = crcStream.getValue(); Assert.assertEquals(value1, value2); Assert.assertEquals(crcStream.available(), 0); buf[3999] = (byte) (~buf[3999]); stream = new ByteBufferInputStream(ByteBuffer.wrap(buf)); crcStream = new CrcInputStream(stream); try { crcStream.read(bufOutput, 0, 3999); bufOutput[3999] = (byte) crcStream.read(); } catch (IOException e) { Assert.assertTrue(false); } Assert.assertArrayEquals(buf, bufOutput); long value3 = crcStream.getValue(); Assert.assertFalse(value2 == value3); crcStream.close(); }