@Override public boolean isDone(final PositionalBufferedStream source) { try { return source.isDone(); } catch (final IOException e) { throw new RuntimeException("Failure reading from stream.", e); } } }
@Override public boolean isDone(PositionalBufferedStream positionalBufferedStream) { try { return positionalBufferedStream.isDone(); } catch (IOException e) { log.error(e.getMessage(), e); return true; } }
@Override public boolean isDone(final PositionalBufferedStream source) { try { return source.isDone(); } catch (final IOException e) { throw new RuntimeIOException("Failure reading from stream.", e); } }
@Override public boolean isDone(final PositionalBufferedStream source) { try { return source.isDone(); } catch (final IOException e) { throw new RuntimeIOException("Failure reading from stream.", e); } }
@Override public final long skip(final long nBytes) throws IOException { long remainingToSkip = nBytes; // because we have this buffer, that may be shorter than nBytes // we loop while there are bytes to skip, filling the buffer // When the buffer contains enough data that we have less than // its less left to skip we increase nextChar by the remaining // amount while ( remainingToSkip > 0 && ! isDone() ) { final long bytesLeftInBuffer = nChars - nextChar; if ( remainingToSkip > bytesLeftInBuffer ) { // we need to refill the buffer and continue our skipping remainingToSkip -= bytesLeftInBuffer; fill(); } else { // there are enough bytes in the buffer to not read again // we just push forward the pointer nextChar nextChar += remainingToSkip; remainingToSkip = 0; } } final long actuallySkipped = nBytes - remainingToSkip; position += actuallySkipped; return actuallySkipped; }
@Override public final long skip(final long nBytes) throws IOException { long remainingToSkip = nBytes; // because we have this buffer, that may be shorter than nBytes // we loop while there are bytes to skip, filling the buffer // When the buffer contains enough data that we have less than // its less left to skip we increase nextChar by the remaining // amount while ( remainingToSkip > 0 && ! isDone() ) { final long bytesLeftInBuffer = nChars - nextChar; if ( remainingToSkip > bytesLeftInBuffer ) { // we need to refill the buffer and continue our skipping remainingToSkip -= bytesLeftInBuffer; fill(); } else { // there are enough bytes in the buffer to not read again // we just push forward the pointer nextChar nextChar += remainingToSkip; remainingToSkip = 0; } } final long actuallySkipped = nBytes - remainingToSkip; position += actuallySkipped; return actuallySkipped; }
@Override public boolean hasNext() { try { return !pbs.isDone(); } catch (IOException e) { throw new RuntimeException(e); } }
public final long skip(final long nBytes) throws IOException { long remainingToSkip = nBytes; // because we have this buffer, that may be shorter than nBytes // we loop while there are bytes to skip, filling the buffer // When the buffer contains enough data that we have less than // its less left to skip we increase nextChar by the remaining // amount while ( remainingToSkip > 0 && ! isDone() ) { final long bytesLeftInBuffer = nChars - nextChar; if ( remainingToSkip > bytesLeftInBuffer ) { // we need to refill the buffer and continue our skipping remainingToSkip -= bytesLeftInBuffer; fill(); } else { // there are enough bytes in the buffer to not read again // we just push forward the pointer nextChar nextChar += remainingToSkip; remainingToSkip = 0; } } final long actuallySkipped = nBytes - remainingToSkip; position += actuallySkipped; return actuallySkipped; }
@Test public void testSkip() throws IOException { for ( int skipSizeBase : Arrays.asList(0, 10, 100, 1000, 10000, 1000000)) { for ( int skipSizeAdd = 0; skipSizeAdd < 10; skipSizeAdd ++ ) { final int skipSize = skipSizeBase + skipSizeAdd; final byte[] bytes = new byte[skipSize+2]; Arrays.fill(bytes, 0, skipSize, (byte)0); bytes[skipSize] = 1; bytes[skipSize+1] = 2; final InputStream is = new ByteArrayInputStream(bytes); final PositionalBufferedStream pbs = new PositionalBufferedStream(is); pbs.skip(skipSize); // first value is 1 Assert.assertTrue(! pbs.isDone()); Assert.assertEquals(pbs.getPosition(), skipSize); Assert.assertEquals(pbs.peek(), 1); Assert.assertEquals(pbs.read(), 1); Assert.assertTrue(! pbs.isDone()); Assert.assertEquals(pbs.getPosition(), skipSize + 1); Assert.assertEquals(pbs.peek(), 2); Assert.assertEquals(pbs.read(), 2); Assert.assertTrue(pbs.isDone()); } } }
while ( ! pbs.isDone() ) { Assert.assertTrue(bytePos < bytes.length);
private void testStream(final byte[] bytes) throws IOException { final InputStream is = new ByteArrayInputStream(bytes); final PositionalBufferedStream pbs = new PositionalBufferedStream(is); int bytePos = 0; while ( ! pbs.isDone() ) { Assert.assertTrue(bytePos < bytes.length); // test position Assert.assertEquals(pbs.getPosition(), bytePos); // test peek final byte atPos = bytes[bytePos]; Assert.assertEquals(toByte(pbs.peek()), atPos); // test position Assert.assertEquals(pbs.getPosition(), bytePos); // test read Assert.assertEquals(toByte(pbs.read()), atPos); bytePos++; // test position Assert.assertEquals(pbs.getPosition(), bytePos); // test repeek if ( bytePos < bytes.length ) { Assert.assertEquals(toByte(pbs.peek()), bytes[bytePos]); // test position Assert.assertEquals(pbs.getPosition(), bytePos); } } Assert.assertEquals(bytePos, bytes.length); pbs.close(); }
while (!headerPbs.isDone()) { VariantContext vc = codec.decode(headerPbs); Assert.assertEquals(vc.getGenotypes().stream().filter(Genotype::isPhased).count(), 2);
while (!bodyPbs.isDone()) { VariantContext vc = codec.decode(bodyPbs); counter++;