@Override public void reset() { compressedOutputStream.reset(); bufferOffset = 0; bufferPosition = 0; }
@Override public String toString(Charset charset) { return toString(); }
private int tryEnsureBatchSize(int length) { ensureWritableBytes(min(MAX_UNUSED_BUFFER_SIZE, length)); return min(length, slice.length() - bufferPosition); }
@Override public void writeZero(int length) { checkArgument(length >= 0, "length must be greater than or equal to 0"); while (length > 0) { int batch = tryEnsureBatchSize(length); Arrays.fill(buffer, bufferPosition, bufferPosition + batch, (byte) 0); bufferPosition += batch; length -= batch; } }
public long estimateOutputDataSize() { return compressedOutputStream.size() + bufferPosition; }
private void ensureWritableBytes(int minWritableBytes) { checkArgument(minWritableBytes <= MAX_UNUSED_BUFFER_SIZE); if (bufferPosition + minWritableBytes > slice.length()) { closeChunk(); } }
@Override public SliceOutput appendByte(int value) { writeByte(value); return this; }
@Override public long getRetainedSize() { return INSTANCE_SIZE + compressedOutputStream.getRetainedSize() + slice.getRetainedSize() + SizeOf.sizeOf(compressionBuffer); }
public OrcOutputBuffer(CompressionKind compression, int maxBufferSize) { requireNonNull(compression, "compression is null"); checkArgument(maxBufferSize > 0, "maximum buffer size should be greater than 0"); this.maxBufferSize = maxBufferSize; this.buffer = new byte[INITIAL_BUFFER_SIZE]; this.slice = wrappedBuffer(buffer); compressedOutputStream = new ChunkedSliceOutput(MINIMUM_OUTPUT_BUFFER_CHUNK_SIZE, MAXIMUM_OUTPUT_BUFFER_CHUNK_SIZE); if (compression == CompressionKind.NONE) { this.compressor = null; } else if (compression == CompressionKind.SNAPPY) { this.compressor = new SnappyCompressor(); } else if (compression == CompressionKind.ZLIB) { this.compressor = new DeflateCompressor(); } else if (compression == CompressionKind.LZ4) { this.compressor = new Lz4Compressor(); } else if (compression == CompressionKind.ZSTD) { this.compressor = new ZstdJniCompressor(); } else { throw new IllegalArgumentException("Unsupported compression " + compression); } }
@Override public void writeInt(int value) { ensureWritableBytes(SIZE_OF_INT); slice.setInt(bufferPosition, value); bufferPosition += SIZE_OF_INT; }
@Override public void writeZero(int length) { checkArgument(length >= 0, "length must be greater than or equal to 0"); while (length > 0) { int batch = tryEnsureBatchSize(length); Arrays.fill(buffer, bufferPosition, bufferPosition + batch, (byte) 0); bufferPosition += batch; length -= batch; } }
public long estimateOutputDataSize() { return compressedOutputStream.size() + bufferPosition; }
private void ensureWritableBytes(int minWritableBytes) { checkArgument(minWritableBytes <= MAX_UNUSED_BUFFER_SIZE); if (bufferPosition + minWritableBytes > slice.length()) { closeChunk(); } }
@Override public SliceOutput appendByte(int value) { writeByte(value); return this; }
@Override public long getRetainedSize() { return INSTANCE_SIZE + compressedOutputStream.getRetainedSize() + slice.getRetainedSize() + SizeOf.sizeOf(compressionBuffer); }
public OrcOutputBuffer(CompressionKind compression, int maxBufferSize) { requireNonNull(compression, "compression is null"); checkArgument(maxBufferSize > 0, "maximum buffer size should be greater than 0"); this.maxBufferSize = maxBufferSize; this.buffer = new byte[INITIAL_BUFFER_SIZE]; this.slice = wrappedBuffer(buffer); compressedOutputStream = new ChunkedSliceOutput(MINIMUM_OUTPUT_BUFFER_CHUNK_SIZE, MAXIMUM_OUTPUT_BUFFER_CHUNK_SIZE); if (compression == CompressionKind.NONE) { this.compressor = null; } else if (compression == CompressionKind.SNAPPY) { this.compressor = new SnappyCompressor(); } else if (compression == CompressionKind.ZLIB) { this.compressor = new DeflateCompressor(); } else if (compression == CompressionKind.LZ4) { this.compressor = new Lz4Compressor(); } else if (compression == CompressionKind.ZSTD) { this.compressor = new ZstdJniCompressor(); } else { throw new IllegalArgumentException("Unsupported compression " + compression); } }
@Override public void writeLong(long value) { ensureWritableBytes(SIZE_OF_LONG); slice.setLong(bufferPosition, value); bufferPosition += SIZE_OF_LONG; }
@Override public void writeBytes(InputStream in, int length) throws IOException { while (length > 0) { int batch = tryEnsureBatchSize(length); slice.setBytes(bufferPosition, in, batch); bufferPosition += batch; length -= batch; } }
public long getOutputDataSize() { checkState(bufferPosition == 0, "Buffer must be flushed before getOutputDataSize can be called"); return compressedOutputStream.size(); }