public void seek(final long pPosition) throws IOException { seekable.seek(pPosition); }
@Override public final void reset() throws IOException { checkOpen(); if (!markedPositions.isEmpty()) { long newPos = markedPositions.pop(); // NOTE: This is correct according to javax.imageio (IOException), // but it's kind of inconsistent with seek that throws IndexOutOfBoundsException... if (newPos < flushedPosition) { throw new IOException("Previous marked position has been discarded"); } seek(newPos); } else { // TODO: To iron out some wrinkles due to conflicting contracts // (InputStream and Seekable both declare reset), // we might need to reset to the last marked position instead.. // However, that becomes REALLY confusing if that position is after // the current position... seek(0); } }
seek(Math.min(wantedPosition, pos + available));
protected void testSeekSkip(SeekableInputStream pSeekable, String pStr) throws IOException { System.out.println(); pSeekable.seek(pStr.length()); FileUtil.read(pSeekable); for (int i = 0; i < 10; i++) { byte[] bytes = FileUtil.read(pSeekable); int len = bytes.length; if (len != 0) { System.err.println("Error in buffer length after full read..."); System.err.println("len: " + len); System.err.println("bytes: \"" + new String(bytes) + "\""); break; } } System.out.println(); for (int i = 0; i < 10; i++) { pSeekable.seek(0); int skip = i * 3; //noinspection ResultOfMethodCallIgnored pSeekable.skip(skip); String str = new String(FileUtil.read(pSeekable)); System.out.println(str); if (str.length() != pStr.length() - skip) { throw new Error("Error in buffer length after skip"); } } System.out.println(); System.out.println("seek/skip ok!"); System.out.println(); }
@Test public void testSeekFlush() throws Exception { SeekableInputStream seekable = makeInputStream(133); int pos = 45; seekable.seek(pos); seekable.flushBefore(pos); long flushedPos = seekable.getFlushedPosition(); assertEquals("Flushed positon should match position", pos, flushedPos); try { seekable.seek(pos - 1); fail("Read before flushed position succeeded"); } catch (IndexOutOfBoundsException e) { // Ignore } }
@Test public void testSeek() throws Exception { SeekableInputStream seekable = makeInputStream(55); int pos = 37; seekable.seek(pos); long streamPos = seekable.getStreamPosition(); assertEquals("Stream positon should match seeked position", pos, streamPos); }
public void seek(final long pPosition) throws IOException { seekable.seek(pPosition); }
public void seek(final long pPosition) throws IOException { mSeekable.seek(pPosition); }
@Test public void testSeekSkipRead() throws Exception { SeekableInputStream seekable = makeInputStream(133); int pos = 45; for (int i = 0; i < 10; i++) { seekable.seek(pos); //noinspection ResultOfMethodCallIgnored seekable.skip(i); byte[] bytes = FileUtil.read(seekable); assertEquals(133, seekable.getStreamPosition()); assertEquals(133 - 45- i, bytes.length); } }
@Test public void testReadAllByteValuesRegression() throws IOException { final int size = 128; // Fill bytes byte[] bytes = new byte[256]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) i; } // Create wrapper stream SeekableInputStream stream = makeInputStream(bytes); // Fill buffer byte[] buffer = new byte[size]; while (stream.read(buffer) >= 0) { } stream.seek(0); for (int i = 0; i < bytes.length; i += 2) { assertEquals("Wrong stream position", i, stream.getStreamPosition()); int count = stream.read(buffer, 0, 2); assertEquals(2, count); assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i], buffer[0]); assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i + 1], buffer[1]); } stream.seek(0); for (int i = 0; i < bytes.length; i++) { assertEquals("Wrong stream position", i, stream.getStreamPosition()); int actual = stream.read(); assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i] & 0xff, actual); assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i], (byte) actual); } }
@Test public void testMarkFlushReset() throws Exception { SeekableInputStream seekable = makeInputStream(77); seekable.mark(); int position = 55; seekable.seek(position); seekable.flushBefore(position); try { seekable.reset(); fail("Reset before flushed position succeeded"); } catch (IOException e) { // Ignore } assertEquals(position, seekable.getStreamPosition()); }
@Test public void testReadResetReadDirectBufferBug() throws IOException { // Make sure we use the exact size of the buffer final int size = 1024; // Fill bytes byte[] bytes = new byte[size * 2]; sRandom.nextBytes(bytes); // Create wrapper stream SeekableInputStream stream = makeInputStream(bytes); // Read to fill the buffer, then reset int val; val = stream.read(); assertFalse("Unexepected EOF", val == -1); val = stream.read(); assertFalse("Unexepected EOF", val == -1); val = stream.read(); assertFalse("Unexepected EOF", val == -1); val = stream.read(); assertFalse("Unexepected EOF", val == -1); stream.seek(0); // Read fully and compare byte[] result = new byte[size]; readFully(stream, result); assertTrue(rangeEquals(bytes, 0, result, 0, size)); readFully(stream, result); assertTrue(rangeEquals(bytes, size, result, 0, size)); }
public void testSeek() throws Exception { SeekableInputStream seekable = makeInputStream(55); int pos = 37; seekable.seek(pos); long streamPos = seekable.getStreamPosition(); assertEquals("Stream positon should match seeked position", pos, streamPos); }
public void testSeekFlush() throws Exception { SeekableInputStream seekable = makeInputStream(133); int pos = 45; seekable.seek(pos); seekable.flushBefore(pos); long flushedPos = seekable.getFlushedPosition(); assertEquals("Flushed positon should match position", pos, flushedPos); try { seekable.seek(pos - 1); fail("Read before flushed position succeeded"); } catch (IndexOutOfBoundsException e) { // Ignore } }
@Test public void testSeekFlush() throws Exception { SeekableInputStream seekable = makeInputStream(133); int pos = 45; seekable.seek(pos); seekable.flushBefore(pos); long flushedPos = seekable.getFlushedPosition(); assertEquals("Flushed positon should match position", pos, flushedPos); try { seekable.seek(pos - 1); fail("Read before flushed position succeeded"); } catch (IndexOutOfBoundsException e) { // Ignore } }
@Test public void testSeek() throws Exception { SeekableInputStream seekable = makeInputStream(55); int pos = 37; seekable.seek(pos); long streamPos = seekable.getStreamPosition(); assertEquals("Stream positon should match seeked position", pos, streamPos); }
public void testSeekSkipRead() throws Exception { SeekableInputStream seekable = makeInputStream(133); int pos = 45; for (int i = 0; i < 10; i++) { seekable.seek(pos); //noinspection ResultOfMethodCallIgnored seekable.skip(i); byte[] bytes = FileUtil.read(seekable); assertEquals(133, seekable.getStreamPosition()); assertEquals(133 - 45- i, bytes.length); } }
@Test public void testSeekSkipRead() throws Exception { SeekableInputStream seekable = makeInputStream(133); int pos = 45; for (int i = 0; i < 10; i++) { seekable.seek(pos); //noinspection ResultOfMethodCallIgnored seekable.skip(i); byte[] bytes = FileUtil.read(seekable); assertEquals(133, seekable.getStreamPosition()); assertEquals(133 - 45- i, bytes.length); } }
public void testMarkFlushReset() throws Exception { SeekableInputStream seekable = makeInputStream(77); seekable.mark(); int position = 55; seekable.seek(position); seekable.flushBefore(position); try { seekable.reset(); fail("Reset before flushed position succeeded"); } catch (IOException e) { // Ignore } assertEquals(position, seekable.getStreamPosition()); }
@Test public void testMarkFlushReset() throws Exception { SeekableInputStream seekable = makeInputStream(77); seekable.mark(); int position = 55; seekable.seek(position); seekable.flushBefore(position); try { seekable.reset(); fail("Reset before flushed position succeeded"); } catch (IOException e) { // Ignore } assertEquals(position, seekable.getStreamPosition()); }