@Test public void testReadSeek() throws IOException { byte[] data = new byte[1024 * 18]; random.nextBytes(data); ByteArrayImageInputStream stream = new ByteArrayImageInputStream(data); assertEquals("Data length should be same as stream length", data.length, stream.length()); byte[] result = new byte[9]; for (int i = 0; i < data.length / result.length; i++) { // Read backwards long newPos = stream.length() - result.length - i * result.length; stream.seek(newPos); assertEquals("Wrong stream position", newPos, stream.getStreamPosition()); stream.readFully(result); assertTrue("Wrong data read: " + i, rangeEquals(data, (int) newPos, result, 0, result.length)); } } }
@Test public void testBufferPositionCorrect() throws IOException { // Fill bytes byte[] bytes = new byte[1024]; random.nextBytes(bytes); ByteArrayImageInputStream input = new ByteArrayImageInputStream(bytes); input.readByte(); input.readByte(); input.skipBytes(124); input.readByte(); input.readByte(); // Sanity check assertEquals(128, input.getStreamPosition()); BufferedImageInputStream stream = new BufferedImageInputStream(input); assertEquals(input.getStreamPosition(), stream.getStreamPosition()); stream.skipBytes(128); //assertTrue(256 <= input.getStreamPosition()); assertEquals(256, stream.getStreamPosition()); stream.seek(1020); assertEquals(1020, stream.getStreamPosition()); }
public void testReadSeek() throws IOException { byte[] data = new byte[1024 * 18]; random.nextBytes(data); ByteArrayImageInputStream stream = new ByteArrayImageInputStream(data); assertEquals("Data length should be same as stream length", data.length, stream.length()); byte[] result = new byte[9]; for (int i = 0; i < data.length / result.length; i++) { // Read backwards long newPos = stream.length() - result.length - i * result.length; stream.seek(newPos); assertEquals("Wrong stream position", newPos, stream.getStreamPosition()); stream.readFully(result); assertTrue("Wrong data read: " + i, rangeEquals(data, (int) newPos, result, 0, result.length)); } } }
public void testReadSeek() throws IOException { byte[] data = new byte[1024 * 18]; mRandom.nextBytes(data); ByteArrayImageInputStream stream = new ByteArrayImageInputStream(data); assertEquals("Data length should be same as stream length", data.length, stream.length()); byte[] result = new byte[9]; for (int i = 0; i < data.length / result.length; i++) { // Read backwards long newPos = stream.length() - result.length - i * result.length; stream.seek(newPos); assertEquals("Wrong stream position", newPos, stream.getStreamPosition()); stream.readFully(result); assertTrue("Wrong data read: " + i, rangeEquals(data, (int) newPos, result, 0, result.length)); } } }
public void testBufferPositionCorrect() throws IOException { // Fill bytes byte[] bytes = new byte[1024]; mRandom.nextBytes(bytes); ByteArrayImageInputStream input = new ByteArrayImageInputStream(bytes); input.readByte(); input.readByte(); input.skipBytes(124); input.readByte(); input.readByte(); // Sanity check assertEquals(128, input.getStreamPosition()); BufferedImageInputStream stream = new BufferedImageInputStream(input); assertEquals(input.getStreamPosition(), stream.getStreamPosition()); stream.skipBytes(128); //assertTrue(256 <= input.getStreamPosition()); assertEquals(256, stream.getStreamPosition()); stream.seek(1020); assertEquals(1020, stream.getStreamPosition()); }
public void testBufferPositionCorrect() throws IOException { // Fill bytes byte[] bytes = new byte[1024]; random.nextBytes(bytes); ByteArrayImageInputStream input = new ByteArrayImageInputStream(bytes); input.readByte(); input.readByte(); input.skipBytes(124); input.readByte(); input.readByte(); // Sanity check assertEquals(128, input.getStreamPosition()); BufferedImageInputStream stream = new BufferedImageInputStream(input); assertEquals(input.getStreamPosition(), stream.getStreamPosition()); stream.skipBytes(128); //assertTrue(256 <= input.getStreamPosition()); assertEquals(256, stream.getStreamPosition()); stream.seek(1020); assertEquals(1020, stream.getStreamPosition()); }