public void testReadSubstream() throws IOException { byte[] bytes = new byte[20]; MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input, 9); for (int i = 0; i < 9; i++) { assertTrue("Unexpected end of stream", -1 != stream.read()); } assertEquals("Read value after end of stream", -1, stream.read()); assertEquals("Read value after end of stream", -1, stream.read()); // Make sure we don't read outside stream boundaries assertTrue(input.getStreamPosition() <= 9); input.close(); }
public void testSeekBeforeStreamNoEnd() throws IOException { byte[] bytes = new byte[20]; MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); input.seek(10); assertEquals(10, input.getStreamPosition()); IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input); assertEquals("Should not skip backwards", 0, stream.skip(-5)); assertEquals(10, input.getStreamPosition()); }
public void testSeekBeforeStream() throws IOException { byte[] bytes = new byte[20]; MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); input.seek(10); assertEquals(10, input.getStreamPosition()); IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input, 9); assertEquals("Should not skip backwards", 0, stream.skip(-5)); assertEquals(10, input.getStreamPosition()); } }
public void testReadSubstreamOpenEnd() throws IOException { byte[] bytes = new byte[20]; MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); input.seek(10); assertEquals(10, input.getStreamPosition()); IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input); for (int i = 0; i < 10; i++) { assertTrue("Unexpected end of stream", -1 != stream.read()); } assertEquals("Read value after end of stream", -1, stream.read()); assertEquals("Read value after end of stream", -1, stream.read()); // Make sure underlying stream is positioned at end of substream after close stream.close(); assertEquals(20, input.getStreamPosition()); input.close(); }
public void testReadSubstreamRepositionOnClose() throws IOException { byte[] bytes = new byte[20]; MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input, 10); for (int i = 0; i < 7; i++) { assertTrue("Unexpected end of stream", -1 != stream.read()); } // Make sure we don't read outside stream boundaries assertTrue(input.getStreamPosition() <= 7); // Make sure underlying stream is positioned at end of substream after close stream.close(); assertEquals(10, input.getStreamPosition()); input.close(); }