private SliceInput getDelegate() { if (delegate == null) { delegate = requireNonNull(loader.get(), "loader returned a null stream"); verify(delegate.length() == globalLength, "loader returned stream of length %s, but length %s was expected", delegate.length(), globalLength); delegate.setPosition(initialPosition); } return delegate; }
private void advance() throws IOException if (compressedSliceInput == null || compressedSliceInput.remaining() == 0) { current = null; return; currentCompressedBlockOffset = toIntExact(compressedSliceInput.position()); int b0 = compressedSliceInput.readUnsignedByte(); int b1 = compressedSliceInput.readUnsignedByte(); int b2 = compressedSliceInput.readUnsignedByte(); if (chunkLength < 0 || chunkLength > compressedSliceInput.remaining()) { throw new OrcCorruptionException(orcDataSourceId, "The chunkLength (%s) must not be negative or greater than remaining size (%s)", chunkLength, compressedSliceInput.remaining()); Slice chunk = compressedSliceInput.readSlice(chunkLength);
@Override public int available() { if (current == null) { return 0; } return current.available(); }
public long getCheckpoint() { // if the decompressed buffer is empty, return a checkpoint starting at the next block if (current == null || (current.position() == 0 && current.remaining() == 0)) { return createInputStreamCheckpoint(toIntExact(compressedSliceInput.position()), 0); } // otherwise return a checkpoint at the last compressed block read and the current position in the buffer return createInputStreamCheckpoint(currentCompressedBlockOffset, toIntExact(current.position())); }
public boolean seekToCheckpoint(long checkpoint) throws IOException { int compressedBlockOffset = decodeCompressedBlockOffset(checkpoint); int decompressedOffset = decodeDecompressedOffset(checkpoint); boolean discardedBuffer; if (compressedBlockOffset != currentCompressedBlockOffset) { if (!decompressor.isPresent()) { throw new OrcCorruptionException(orcDataSourceId, "Reset stream has a compressed block offset but stream is not compressed"); } compressedSliceInput.setPosition(compressedBlockOffset); current = EMPTY_SLICE.getInput(); discardedBuffer = true; } else { discardedBuffer = false; } if (decompressedOffset != current.position()) { current.setPosition(0); if (current.remaining() < decompressedOffset) { decompressedOffset -= current.remaining(); advance(); } current.setPosition(decompressedOffset); } return discardedBuffer; }
@Override public long position() { if (delegate == null) { return initialPosition; } return delegate.position(); }
@Override public int read() throws IOException { if (current == null) { return -1; } int result = current.read(); if (result != -1) { return result; } advance(); return read(); }
@Override public void setPosition(long position) { if (delegate == null) { if (position < 0 || position > globalLength) { throw new IndexOutOfBoundsException("Invalid position " + position + " for slice with length " + globalLength); } initialPosition = toIntExact(position); return; } delegate.setPosition(position); }
@Override public void close() throws IOException { current = null; fixedMemoryUsage.setBytes(compressedSliceInput.length()); // see comments above for fixedMemoryUsage buffer = null; bufferMemoryUsage.setBytes(0); }
@Override public boolean isReadable() { if (delegate == null) { return true; } return delegate.isReadable(); }
public boolean seekToCheckpoint(long checkpoint) throws IOException { int compressedBlockOffset = decodeCompressedBlockOffset(checkpoint); int decompressedOffset = decodeDecompressedOffset(checkpoint); boolean discardedBuffer; if (compressedBlockOffset != currentCompressedBlockOffset) { if (compressionKind == UNCOMPRESSED) { throw new OrcCorruptionException("Reset stream has a compressed block offset but stream is not compressed"); } compressedSliceInput.setPosition(compressedBlockOffset); current = EMPTY_SLICE.getInput(); discardedBuffer = true; } else { discardedBuffer = false; } if (decompressedOffset != current.position()) { current.setPosition(0); if (current.remaining() < decompressedOffset) { decompressedOffset -= current.remaining(); advance(); } current.setPosition(decompressedOffset); } return discardedBuffer; }
public long getCheckpoint() { // if the decompressed buffer is empty, return a checkpoint starting at the next block if (current == null || (current.position() == 0 && current.remaining() == 0)) { return createInputStreamCheckpoint(toIntExact(compressedSliceInput.position()), 0); } // otherwise return a checkpoint at the last compressed block read and the current position in the buffer return createInputStreamCheckpoint(currentCompressedBlockOffset, toIntExact(current.position())); }
@Override public String toString() { return toStringHelper(this) .add("source", orcDataSourceId) .add("compressedOffset", compressedSliceInput.position()) .add("uncompressedOffset", current == null ? null : current.position()) .add("decompressor", decompressor.map(Object::toString).orElse("none")) .toString(); } }
@Override public int read() throws IOException { if (current == null) { return -1; } int result = current.read(); if (result != -1) { return result; } advance(); return read(); }