Package org.apache.parquet.bytes
Class BytesInput
- java.lang.Object
-
- org.apache.parquet.bytes.BytesInput
-
- Direct Known Subclasses:
ConcatenatingByteArrayCollector,ConcatenatingByteBufferCollector
public abstract class BytesInput extends Object
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 Constructor Description BytesInput()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static BytesInputconcat(List<BytesInput> inputs)logically concatenate the provided inputsstatic BytesInputconcat(BytesInput... inputs)logically concatenate the provided inputsBytesInputcopy(ByteBufferAllocator allocator, Consumer<ByteBuffer> callback)Copies the content of thisBytesInputobject to a newly createdByteBufferand returns it wrapped in aBytesInputobject.BytesInputcopy(ByteBufferReleaser releaser)Similar tocopy(ByteBufferAllocator, Consumer)where the allocator and the callback are in the specifiedByteBufferReleaser.static BytesInputcopy(BytesInput bytesInput)Deprecated.Usecopy(ByteBufferAllocator, Consumer)insteadstatic 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[]toByteArray()Deprecated.ByteBuffertoByteBuffer()Deprecated.ByteBuffertoByteBuffer(ByteBufferAllocator allocator, Consumer<ByteBuffer> callback)Returns aByteBufferobject referencing the data behind thisBytesInputobject.ByteBuffertoByteBuffer(ByteBufferReleaser releaser)Similar totoByteBuffer(ByteBufferAllocator, Consumer)where the allocator and the callback are in the specifiedByteBufferReleaser.ByteBufferInputStreamtoInputStream()abstract voidwriteAllTo(OutputStream out)writes the bytes into a stream
-
-
-
Method Detail
-
concat
public static BytesInput concat(BytesInput... inputs)
logically concatenate the provided inputs- Parameters:
inputs- the inputs to concatenate- Returns:
- a concatenated input
-
concat
public static BytesInput concat(List<BytesInput> inputs)
logically concatenate the provided inputs- Parameters:
inputs- the inputs to concatenate- Returns:
- a concatenated input
-
from
public static BytesInput from(InputStream in, int bytes)
- 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 public static BytesInput from(ByteBuffer buffer, int offset, int length)
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
public static BytesInput from(ByteBuffer... buffers)
- Parameters:
buffers- an array of byte buffers- Returns:
- a BytesInput that will read the given bytes from the ByteBuffers
-
from
public static BytesInput from(List<ByteBuffer> buffers)
- Parameters:
buffers- a list of byte buffers- Returns:
- a BytesInput that will read the given bytes from the ByteBuffers
-
from
public static BytesInput from(byte[] in)
- Parameters:
in- a byte array- Returns:
- a Bytes input that will write the given bytes
-
from
public static BytesInput from(byte[] in, int offset, int length)
-
fromInt
public static BytesInput fromInt(int intValue)
- Parameters:
intValue- the int to write- Returns:
- a BytesInput that will write 4 bytes in little endian
-
fromUnsignedVarInt
public static BytesInput fromUnsignedVarInt(int intValue)
- Parameters:
intValue- the int to write- Returns:
- a BytesInput that will write var int
-
fromZigZagVarInt
public static BytesInput fromZigZagVarInt(int intValue)
- Parameters:
intValue- the int to write- Returns:
- a ByteInput that contains the int value as a variable-length zig-zag encoded int
-
fromUnsignedVarLong
public static BytesInput fromUnsignedVarLong(long longValue)
- Parameters:
longValue- the long to write- Returns:
- a BytesInput that will write var long
-
fromZigZagVarLong
public static BytesInput fromZigZagVarLong(long longValue)
- Parameters:
longValue- the long to write- Returns:
- a ByteInput that contains the long value as a variable-length zig-zag encoded long
-
from
public static BytesInput from(CapacityByteArrayOutputStream arrayOut)
- 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
public static BytesInput from(ByteArrayOutputStream baos)
- Parameters:
baos- - stream to wrap into a BytesInput- Returns:
- a BytesInput that will write the content of the buffer
-
empty
public static BytesInput empty()
- Returns:
- an empty bytes input
-
copy
@Deprecated public static BytesInput copy(BytesInput bytesInput) throws IOException
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
public abstract void writeAllTo(OutputStream out) throws IOException
writes the bytes into a stream- Parameters:
out- an output stream- Throws:
IOException- if there is an exception writing
-
toByteArray
@Deprecated public byte[] toByteArray() throws IOException
Deprecated.- Returns:
- a new byte array materializing the contents of this input
- Throws:
IOException- if there is an exception reading
-
toByteBuffer
@Deprecated public ByteBuffer toByteBuffer() throws IOException
Deprecated.- Returns:
- a new ByteBuffer materializing the contents of this input
- Throws:
IOException- if there is an exception reading
-
copy
public BytesInput copy(ByteBufferAllocator allocator, Consumer<ByteBuffer> callback)
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
public BytesInput copy(ByteBufferReleaser releaser)
Similar tocopy(ByteBufferAllocator, Consumer)where the allocator and the callback are in the specifiedByteBufferReleaser.
-
toByteBuffer
public ByteBuffer toByteBuffer(ByteBufferAllocator allocator, Consumer<ByteBuffer> callback)
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
public ByteBuffer toByteBuffer(ByteBufferReleaser releaser)
Similar totoByteBuffer(ByteBufferAllocator, Consumer)where the allocator and the callback are in the specifiedByteBufferReleaser.
-
toInputStream
public ByteBufferInputStream toInputStream() throws IOException
- 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
-
-