@Override public long getBytesConsumed() { return byteCountingIn.getBytesConsumed(); }
@Override public int getBlockIndex() { if (tocReader == null) { throw new IllegalStateException("Cannot determine Block Index because no Table-of-Contents could be found for Provenance Log " + filename); } return tocReader.getBlockIndex(rawInputStream.getBytesConsumed()); }
@Override public void skipTo(final long position) throws IOException { // we are subtracting headerLength from the number of bytes consumed because we used to // consider the offset of the first record "0" - now we consider it whatever position it // it really is in the stream. final long currentPosition = byteCountingIn.getBytesConsumed() - headerLength; if (currentPosition == position) { return; } if (currentPosition > position) { throw new IOException("Cannot skip to byte offset " + position + " in stream because already at byte offset " + currentPosition); } final long toSkip = position - currentPosition; StreamUtils.skip(dis, toSkip); }
private void resetStreamForNextBlock() throws IOException { final InputStream limitedStream; if (tocReader == null) { limitedStream = rawInputStream; } else { final long offset = tocReader.getBlockOffset(1 + getBlockIndex()); if (offset < 0) { limitedStream = rawInputStream; } else { limitedStream = new LimitingInputStream(rawInputStream, offset - rawInputStream.getBytesConsumed()); } } final InputStream readableStream; if (compressed) { readableStream = new BufferedInputStream(new GZIPInputStream(limitedStream)); } else { readableStream = new BufferedInputStream(limitedStream); } byteCountingIn = new ByteCountingInputStream(readableStream, rawInputStream.getBytesConsumed()); dis = new DataInputStream(byteCountingIn); }
limitedStream = rawInputStream; } else { limitedStream = new LimitingInputStream(rawInputStream, offset1 - rawInputStream.getBytesConsumed());
final ByteCountingInputStream in = new ByteCountingInputStream(bufferedIn)) { long messageStartOffset = in.getBytesConsumed(); final long messageEndOffset = in.getBytesConsumed(); messageStartOffset = in.getBytesConsumed();
@Override public void skipToBlock(final int blockIndex) throws IOException { if (tocReader == null) { throw new IllegalStateException("Cannot skip to block " + blockIndex + " for Provenance Log " + filename + " because no Table-of-Contents file was found for this Log"); } if (blockIndex < 0) { throw new IllegalArgumentException("Cannot skip to block " + blockIndex + " because the value is negative"); } if (blockIndex == getBlockIndex()) { return; } final long offset = tocReader.getBlockOffset(blockIndex); if (offset < 0) { throw new IOException("Unable to find block " + blockIndex + " in Provenance Log " + filename); } final long curOffset = rawInputStream.getBytesConsumed(); final long bytesToSkip = offset - curOffset; if (bytesToSkip >= 0) { try { StreamUtils.skip(rawInputStream, bytesToSkip); logger.debug("Skipped stream from offset {} to {} ({} bytes skipped)", curOffset, offset, bytesToSkip); } catch (final EOFException eof) { throw new EOFException("Attempted to skip to byte offset " + offset + " for " + filename + " but file does not have that many bytes (TOC Reader=" + getTocReader() + ")"); } catch (final IOException e) { throw new IOException("Failed to skip to offset " + offset + " for block " + blockIndex + " of Provenance Log " + filename, e); } resetStreamForNextBlock(); } }
if (currentReadClaimStream != null && currentReadClaimStream.getBytesConsumed() <= offset) { final long bytesToSkip = offset - currentReadClaimStream.getBytesConsumed(); if (bytesToSkip > 0) { StreamUtils.skip(currentReadClaimStream, bytesToSkip);