@NonNull @Override public InputStream rewindAndGet() throws IOException { bufferedStream.reset(); return bufferedStream; }
@Test(expected = RecyclableBufferedInputStream.InvalidMarkException.class) public void testResetThrowsIfMarkNotSet() throws IOException { stream.reset(); }
@Test public void testCallsResetOnWrapped() throws IOException { is.reset(); verify(wrapped).reset(); }
@Test(expected = IOException.class) public void testResetThrowsIfStreamIsClosed() throws IOException { stream.close(); stream.reset(); }
@Test(expected = RecyclableBufferedInputStream.InvalidMarkException.class) public void testResetThrowsIfMarkIsInvalid() throws IOException { stream.mark(1); stream.read(new byte[BUFFER_SIZE], 0, BUFFER_SIZE); stream.read(); stream.reset(); } }
@Test public void testCanResetRepeatedlyAfterMarking() throws IOException { byte[] buffer = new byte[BUFFER_SIZE]; stream.mark(BUFFER_SIZE); for (int repeat = 0; repeat < 10; repeat++) { assertEquals(BUFFER_SIZE, stream.read(buffer, 0, BUFFER_SIZE)); for (int i = 0; i < BUFFER_SIZE; i++) { assertEquals(i, buffer[i]); } stream.reset(); } }
@Test public void testCanMarkAndReset() throws IOException { byte[] buffer = new byte[BUFFER_SIZE]; stream.mark(BUFFER_SIZE); assertEquals(BUFFER_SIZE, stream.read(buffer, 0, BUFFER_SIZE)); for (int i = 0; i < BUFFER_SIZE; i++) { assertEquals(i, buffer[i]); } Arrays.fill(buffer, (byte) 0); stream.reset(); assertEquals(BUFFER_SIZE, stream.read(buffer, 0, BUFFER_SIZE)); for (int i = 0; i < BUFFER_SIZE; i++) { assertEquals(i, buffer[i]); } }
@Test public void testCanMarkInMiddleOfBufferAndStillReadUpToBufferLengthBeforeResetting() throws IOException { int markPos = BUFFER_SIZE / 2; for (int i = 0; i < markPos; i++) { stream.read(); } stream.mark(BUFFER_SIZE); for (int i = 0; i < BUFFER_SIZE; i++) { stream.read(); } stream.reset(); assertEquals(markPos, stream.read()); }
@Override public InputStream rewindAndGet() throws IOException { bufferedStream.reset(); return bufferedStream; }