Package org.apache.parquet.bytes
Class BytesInput
java.lang.Object
org.apache.parquet.bytes.BytesInput
- Direct Known Subclasses:
ConcatenatingByteArrayCollector,ConcatenatingByteBufferCollector
A source of bytes capable of writing itself to an output.
A BytesInput should be consumed right away.
It is not a container.
For example if it is referring to a stream,
subsequent BytesInput reads from the stream will be incorrect
if the previous has not been consumed.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BytesInputconcat(List<BytesInput> inputs) logically concatenate the provided inputsstatic BytesInputconcat(BytesInput... inputs) logically concatenate the provided inputscopy(ByteBufferAllocator allocator, Consumer<ByteBuffer> callback) Copies the content of thisBytesInputobject to a newly createdByteBufferand returns it wrapped in aBytesInputobject.copy(ByteBufferReleaser releaser) Similar tocopy(ByteBufferAllocator, Consumer)where the allocator and the callback are in the specifiedByteBufferReleaser.static BytesInputcopy(BytesInput bytesInput) Deprecated.static BytesInputempty()static BytesInputfrom(byte[] in) static BytesInputfrom(byte[] in, int offset, int length) static BytesInputfrom(ByteArrayOutputStream baos) static BytesInputfrom(InputStream in, int bytes) static BytesInputfrom(ByteBuffer... buffers) static BytesInputfrom(ByteBuffer buffer, int offset, int length) Deprecated.Will be removed in 2.0.0static BytesInputfrom(List<ByteBuffer> buffers) static BytesInputfrom(CapacityByteArrayOutputStream arrayOut) static BytesInputfromInt(int intValue) static BytesInputfromUnsignedVarInt(int intValue) static BytesInputfromUnsignedVarLong(long longValue) static BytesInputfromZigZagVarInt(int intValue) static BytesInputfromZigZagVarLong(long longValue) abstract longsize()byte[]Deprecated.Deprecated.toByteBuffer(ByteBufferAllocator allocator, Consumer<ByteBuffer> callback) Returns aByteBufferobject referencing the data behind thisBytesInputobject.toByteBuffer(ByteBufferReleaser releaser) Similar totoByteBuffer(ByteBufferAllocator, Consumer)where the allocator and the callback are in the specifiedByteBufferReleaser.abstract voidwriteAllTo(OutputStream out) writes the bytes into a stream
-
Constructor Details
-
BytesInput
public BytesInput()
-
-
Method Details
-
concat
logically concatenate the provided inputs- Parameters:
inputs- the inputs to concatenate- Returns:
- a concatenated input
-
concat
logically concatenate the provided inputs- Parameters:
inputs- the inputs to concatenate- Returns:
- a concatenated input
-
from
- Parameters:
in- an input streambytes- number of bytes to read- Returns:
- a BytesInput that will read that number of bytes from the stream
-
from
Deprecated.Will be removed in 2.0.0- Parameters:
buffer-length- number of bytes to read- Returns:
- a BytesInput that will read the given bytes from the ByteBuffer
-
from
- Parameters:
buffers- an array of byte buffers- Returns:
- a BytesInput that will read the given bytes from the ByteBuffers
-
from
- Parameters:
buffers- a list of byte buffers- Returns:
- a BytesInput that will read the given bytes from the ByteBuffers
-
from
- Parameters:
in- a byte array- Returns:
- a Bytes input that will write the given bytes
-
from
-
fromInt
- Parameters:
intValue- the int to write- Returns:
- a BytesInput that will write 4 bytes in little endian
-
fromUnsignedVarInt
- Parameters:
intValue- the int to write- Returns:
- a BytesInput that will write var int
-
fromZigZagVarInt
- Parameters:
intValue- the int to write- Returns:
- a ByteInput that contains the int value as a variable-length zig-zag encoded int
-
fromUnsignedVarLong
- Parameters:
longValue- the long to write- Returns:
- a BytesInput that will write var long
-
fromZigZagVarLong
- Parameters:
longValue- the long to write- Returns:
- a ByteInput that contains the long value as a variable-length zig-zag encoded long
-
from
- Parameters:
arrayOut- a capacity byte array output stream to wrap into a BytesInput- Returns:
- a BytesInput that will write the content of the buffer
-
from
- Parameters:
baos- - stream to wrap into a BytesInput- Returns:
- a BytesInput that will write the content of the buffer
-
empty
- Returns:
- an empty bytes input
-
copy
Deprecated.Usecopy(ByteBufferAllocator, Consumer)insteadcopies the input into a new byte array- Parameters:
bytesInput- a BytesInput- Returns:
- a copy of the BytesInput
- Throws:
IOException- if there is an exception when reading bytes from the BytesInput
-
writeAllTo
writes the bytes into a stream- Parameters:
out- an output stream- Throws:
IOException- if there is an exception writing
-
toByteArray
Deprecated.- Returns:
- a new byte array materializing the contents of this input
- Throws:
IOException- if there is an exception reading
-
toByteBuffer
Deprecated.- Returns:
- a new ByteBuffer materializing the contents of this input
- Throws:
IOException- if there is an exception reading
-
copy
Copies the content of thisBytesInputobject to a newly createdByteBufferand returns it wrapped in aBytesInputobject. The data content shall be able to be fit in aByteBufferobject! (In case of the size of thisBytesInputobject cannot fit in anint, anArithmeticExceptionwill be thrown. Theallocatormight throw anOutOfMemoryErrorif it is unable to allocate the requiredByteBuffer.)- Parameters:
allocator- the allocator to be used for creating the newByteBufferobjectcallback- the callback called with the newly createdByteBufferobject; to be used for make it released at the proper time- Returns:
- the newly created
BytesInputobject wrapping the copied content of the specified one
-
copy
Similar tocopy(ByteBufferAllocator, Consumer)where the allocator and the callback are in the specifiedByteBufferReleaser. -
toByteBuffer
Returns aByteBufferobject referencing the data behind thisBytesInputobject. It may create a newByteBufferobject if thisBytesInputis not backed by a singleByteBuffer. In the latter case the specifiedByteBufferAllocatorobject will be used. In case of allocation the specified callback will be invoked so the release of the newly allocatedByteBufferobject can be released at a proper time. The data content shall be able to be fit in aByteBufferobject! (In case of the size of thisBytesInputobject cannot fit in anint, anArithmeticExceptionwill be thrown. Theallocatormight throw anOutOfMemoryErrorif it is unable to allocate the requiredByteBuffer.)- Parameters:
allocator- theByteBufferAllocatorto be used for potentially allocating a newByteBufferobjectcallback- the callback to be called with the newByteBufferobject potentially allocated- Returns:
- the
ByteBufferobject with the data content of thisBytesInputobject. (Might be a copy of the content or directly referencing the same memory as thisBytesInputobject.)
-
toByteBuffer
Similar totoByteBuffer(ByteBufferAllocator, Consumer)where the allocator and the callback are in the specifiedByteBufferReleaser. -
toInputStream
- Returns:
- a new InputStream materializing the contents of this input
- Throws:
IOException- if there is an exception reading
-
size
public abstract long size()- Returns:
- the size in bytes that would be written
-
copy(ByteBufferAllocator, Consumer)instead