/** * Creates an {@code InputStream} adapter that reads from an underlying {@code ImageInputStream}. * The input stream will read until the end of {@code pStream}. * * @param pStream the stream to read from. * @return an {@code InputStream} reading from {@code pStream}. */ public static InputStream createStreamAdapter(final ImageInputStream pStream) { // TODO: Include stream start pos? // TODO: Skip buffering for known in-memory implementations? return new BufferedInputStream(new IIOInputStreamAdapter(pStream)); }
/** * Creates an {@code InputStream} adapter that reads from an underlying {@code ImageInputStream}. * The input stream will read until the end of {@code pStream}, or at most {@code pLength} bytes has been read. * * @param pStream the stream to read from. * @param pLength the maximum number of bytes that can be read from {@code pStream}. * @return an {@code InputStream} reading from {@code pStream}. */ public static InputStream createStreamAdapter(final ImageInputStream pStream, final long pLength) { // TODO: Include stream start pos? // TODO: Skip buffering for known in-memory implementations? return new BufferedInputStream(new IIOInputStreamAdapter(pStream, pLength)); }
@Test(expected = IllegalArgumentException.class) public void testCreateNull() { new IIOInputStreamAdapter(null); }
protected InputStream makeInputStream(byte[] pBytes) { return new IIOInputStreamAdapter(new MemoryCacheImageInputStream(new ByteArrayInputStream(pBytes)), pBytes.length); }
@Test 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()); }
@Test 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()); } }
/** * Creates an {@code InputStream} adapter that reads from an underlying {@code ImageInputStream}. * The input stream will read until the end of {@code pStream}. * * @param pStream the stream to read from. * @return an {@code InputStream} reading from {@code pStream}. */ public static InputStream createStreamAdapter(final ImageInputStream pStream) { // TODO: Include stream start pos? // TODO: Skip buffering for known in-memory implementations? return new BufferedInputStream(new IIOInputStreamAdapter(pStream)); }
/** * Creates an {@code InputStream} adapter that reads from an underlying {@code ImageInputStream}. * The input stream will read until the end of {@code pStream}. * * @param pStream the stream to read from. * @return an {@code InputStream} reading from {@code pStream}. */ public static InputStream createStreamAdapter(final ImageInputStream pStream) { // TODO: Include stream start pos? // TODO: Skip buffering for known in-memory implementations? return new BufferedInputStream(new IIOInputStreamAdapter(pStream)); }
/** * Creates an {@code InputStream} adapter that reads from an underlying {@code ImageInputStream}. * The input stream will read until the end of {@code pStream}, or at most {@code pLength} bytes has been read. * * @param pStream the stream to read from. * @param pLength the maximum number of bytes that can be read from {@code pStream}. * @return an {@code InputStream} reading from {@code pStream}. */ public static InputStream createStreamAdapter(final ImageInputStream pStream, final long pLength) { // TODO: Include stream start pos? // TODO: Skip buffering for known in-memory implementations? return new BufferedInputStream(new IIOInputStreamAdapter(pStream, pLength)); }
/** * Creates an {@code InputStream} adapter that reads from an underlying {@code ImageInputStream}. * The input stream will read until the end of {@code pStream}, or at most {@code pLength} bytes has been read. * * @param pStream the stream to read from. * @param pLength the maximum number of bytes that can be read from {@code pStream}. * @return an {@code InputStream} reading from {@code pStream}. */ public static InputStream createStreamAdapter(final ImageInputStream pStream, final long pLength) { // TODO: Include stream start pos? // TODO: Skip buffering for known in-memory implementations? return new BufferedInputStream(new IIOInputStreamAdapter(pStream, pLength)); }
@Test 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(); }
@Test 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(); }
@Test 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(); }
protected InputStream makeInputStream(byte[] pBytes) { return new IIOInputStreamAdapter(new MemoryCacheImageInputStream(new ByteArrayInputStream(pBytes)), pBytes.length); }
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()); } }
@Test 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()); } }
@Test 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 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(); }
@Test 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(); }