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 Details

    • BytesInput

      public BytesInput()
  • Method Details

    • 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 stream
      bytes - 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.
      copies 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
      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
      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 this BytesInput object to a newly created ByteBuffer and returns it wrapped in a BytesInput object. The data content shall be able to be fit in a ByteBuffer object! (In case of the size of this BytesInput object cannot fit in an int, an ArithmeticException will be thrown. The allocator might throw an OutOfMemoryError if it is unable to allocate the required ByteBuffer.)
      Parameters:
      allocator - the allocator to be used for creating the new ByteBuffer object
      callback - the callback called with the newly created ByteBuffer object; to be used for make it released at the proper time
      Returns:
      the newly created BytesInput object wrapping the copied content of the specified one
    • copy

      public BytesInput copy(ByteBufferReleaser releaser)
      Similar to copy(ByteBufferAllocator, Consumer) where the allocator and the callback are in the specified ByteBufferReleaser.
    • toByteBuffer

      public ByteBuffer toByteBuffer(ByteBufferAllocator allocator, Consumer<ByteBuffer> callback)
      Returns a ByteBuffer object referencing the data behind this BytesInput object. It may create a new ByteBuffer object if this BytesInput is not backed by a single ByteBuffer. In the latter case the specified ByteBufferAllocator object will be used. In case of allocation the specified callback will be invoked so the release of the newly allocated ByteBuffer object can be released at a proper time. The data content shall be able to be fit in a ByteBuffer object! (In case of the size of this BytesInput object cannot fit in an int, an ArithmeticException will be thrown. The allocator might throw an OutOfMemoryError if it is unable to allocate the required ByteBuffer.)
      Parameters:
      allocator - the ByteBufferAllocator to be used for potentially allocating a new ByteBuffer object
      callback - the callback to be called with the new ByteBuffer object potentially allocated
      Returns:
      the ByteBuffer object with the data content of this BytesInput object. (Might be a copy of the content or directly referencing the same memory as this BytesInput object.)
    • toByteBuffer

      public ByteBuffer toByteBuffer(ByteBufferReleaser releaser)
      Similar to toByteBuffer(ByteBufferAllocator, Consumer) where the allocator and the callback are in the specified ByteBufferReleaser.
    • 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