@Test public void testFlushOnAdapterDoesNotMoveFlushedPositionInBacking() throws IOException { MemoryCacheImageOutputStream backing = new MemoryCacheImageOutputStream(new ByteArrayOutputStream()); IIOOutputStreamAdapter adapter = new IIOOutputStreamAdapter(backing); // Sanity check assertEquals(0, backing.getFlushedPosition()); // Write & flush adapter.write(0xCA); adapter.write(new byte[8]); adapter.write(0xFE); adapter.flush(); // Assertions assertEquals(10, backing.length()); assertEquals(10, backing.getStreamPosition()); assertEquals(0, backing.getFlushedPosition()); // Just make sure we can safely seek back to start and read data back backing.seek(0); assertEquals(0, backing.getStreamPosition()); // If this can be read, I think the contract of flush is also fulfilled (kind of) assertEquals(0xCA, backing.read()); assertEquals(8, backing.skipBytes(8)); assertEquals(0xFE, backing.read()); } }
@Test public void testFlushOnAdapterDoesNotMoveFlushedPositionInBacking() throws IOException { MemoryCacheImageOutputStream backing = new MemoryCacheImageOutputStream(new ByteArrayOutputStream()); IIOOutputStreamAdapter adapter = new IIOOutputStreamAdapter(backing); // Sanity check assertEquals(0, backing.getFlushedPosition()); // Write & flush adapter.write(0xCA); adapter.write(new byte[8]); adapter.write(0xFE); adapter.flush(); // Assertions assertEquals(10, backing.length()); assertEquals(10, backing.getStreamPosition()); assertEquals(0, backing.getFlushedPosition()); // Just make sure we can safely seek back to start and read data back backing.seek(0); assertEquals(0, backing.getStreamPosition()); // If this can be read, I think the contract of flush is also fulfilled (kind of) assertEquals(0xCA, backing.read()); assertEquals(8, backing.skipBytes(8)); assertEquals(0xFE, backing.read()); } }
final byte[] actBytes = new byte[expIfdBytes.length]; stream.seek(startOffset); stream.read(actBytes); Assert.assertArrayEquals(expIfdBytes, actBytes);