Class InputBuffer

All Implemented Interfaces:
Closeable, AutoCloseable

@LimitedPrivate({"HDFS","MapReduce"}) @Unstable public class InputBuffer extends FilterInputStream
A reusable InputStream implementation that reads from an in-memory buffer.

This saves memory over creating a new InputStream and ByteArrayInputStream each time data is read.

Typical usage is something like the following:


 InputBuffer buffer = new InputBuffer();
 while (... loop condition ...) {
   byte[] data = ... get data ...;
   int dataLength = ... get data length ...;
   buffer.reset(data, dataLength);
   ... read buffer using InputStream methods ...
 }
 
See Also:
  • Constructor Details

    • InputBuffer

      public InputBuffer()
      Constructs a new empty buffer.
  • Method Details

    • reset

      public void reset(byte[] input, int length)
      Resets the data that the buffer reads.
      Parameters:
      input - input.
      length - length.
    • reset

      public void reset(byte[] input, int start, int length)
      Resets the data that the buffer reads.
      Parameters:
      input - input.
      start - start.
      length - length.
    • getPosition

      public int getPosition()
      Returns the current position in the input.
      Returns:
      the current position in the input.
    • getLength

      public int getLength()
      Returns the length of the input.
      Returns:
      length of the input.