@Test(expected = IOException.class) public void throwsWhenTailNotSufficient() throws IOException { byte[] data = new byte[TAIL_LENGTH - 1]; TailInputStream tailStream = new TailInputStream(new ByteArrayInputStream(data), TAIL_LENGTH); byte[] temp = new byte[TAIL_LENGTH * 2 + 3]; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); readFully(tailStream, temp, outputStream); tailStream.getTail(); }
@Test public void testReadInLargeIncrements() throws IOException { byte[] temp = new byte[TAIL_LENGTH * 2 + 3]; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); readFully(mTailInputStream, temp, outputStream); byte[] tail = mTailInputStream.getTail(); byte[] readData = outputStream.toByteArray(); TailBufferHelper.verifyDataAndTailMatch(mInputData, readData, tail, TAIL_LENGTH); }
@Test public void testBytesReturnedByUnderlyingStreamIsReduced() throws IOException { InputStream inputStream = new ByteReducingInputStream(mInputStream, 2); TailInputStream tailInputStream = new TailInputStream(inputStream, TAIL_LENGTH); byte[] temp = new byte[TAIL_LENGTH * 2 + 3]; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); readFully(tailInputStream, temp, outputStream); byte[] tail = tailInputStream.getTail(); byte[] readData = outputStream.toByteArray(); TailBufferHelper.verifyDataAndTailMatch(mInputData, readData, tail, TAIL_LENGTH); }