Class AbstractBinaryStoreReader

java.lang.Object
com.illumon.iris.binarystore.AbstractBinaryStoreReader
All Implemented Interfaces:
BinaryStoreReader, TableReader
Direct Known Subclasses:
AbstractBinaryStoreReaderV1, AbstractBinaryStoreReaderV2

public abstract class AbstractBinaryStoreReader extends Object implements TableReader, BinaryStoreReader
This is the common class for the V1 and V2 binary store readers. Extenders must be able to read the header and support the row getter interfaces.
  • Field Details

    • columnTypes

      protected SupportedType[] columnTypes
    • columnNames

      protected String[] columnNames
    • dataBuffer

      protected ByteBuffer dataBuffer
    • rowGetters

      protected RowGetter[] rowGetters
    • typeMetadata

      protected Object[] typeMetadata
    • mask

      protected byte[] mask
  • Method Details

    • getColumnNames

      public String[] getColumnNames()
      Description copied from interface: TableReader
      Get an array of all known column names. These can be used to determine valid column names for use in TableReader.getGetter(String).
      Specified by:
      getColumnNames in interface TableReader
      Returns:
      a new array of all known column names.
    • getColumnType

      public SupportedType getColumnType(String columnName)
      Description copied from interface: TableReader
      Get the SupportedType of the named column.
      Specified by:
      getColumnType in interface TableReader
      Parameters:
      columnName - the name of the column
      Returns:
      the SupportedType value for the named column
    • getTypeMetadataString

      public String getTypeMetadataString(String columnName)
    • getGetter

      public RowGetter getGetter(String name)
      Get the getter for a named column.
      Specified by:
      getGetter in interface TableReader
      Parameters:
      name - the column to get the getter for.
      Returns:
      the getter
      Throws:
      AbstractBinaryStoreReader.MissingGetterException - when the getter does not exist
    • getGetter

      public <T> RowGetter<T> getGetter(String name, Class<T> tClass)
      Description copied from interface: TableReader
      Return a typed RowGetter for the column with the given name. RowGetter.get() will return type tClass.
      Specified by:
      getGetter in interface TableReader
      Parameters:
      name - the column name
      Returns:
      a RowGetter of type tClass
    • readHeader

      protected void readHeader() throws IOException, EofException
      This implementation declares an internal buffer. This version of readHeader uses that internal buffer.
      Throws:
      IOException
      EofException
      See Also:
    • readIntoByteBuffer

      protected void readIntoByteBuffer(int requiredSize, ByteBuffer theBuffer) throws IOException, EofException
      Populates the specified byte buffer from our data source (defined in derived class).
      This default implementation calls readDataBuffer(int, ByteBuffer) and the abstract readData(int, ByteBuffer), but in the BinaryStoreProcessors used by the DIS, the buffer is passed in and no data is actually read.
      The default implementations might compact the buffer via readDataBuffer(int, ByteBuffer), destroying previously-read data in the buffer.
      Parameters:
      requiredSize - how many bytes of data are required to continue processing
      theBuffer - the data buffer to populate
      Throws:
      IOException - if we encounter an EOF mid row
      EofException - if no data is available from the file
    • readDataBuffer

      protected void readDataBuffer(int minAmount, ByteBuffer theBuffer) throws IOException
      Convenience method to manage ByteBuffer pointers as more bytes are added to the buffer.
      The byte buffer will be switched from read mode to write mode and back again. This implementation will compact the buffer (remaining bytes copied to position 0), so position and limit might change.
      The byte buffer will be left in a ready-to-read state.
      Parameters:
      minAmount - add this many bytes to the buffer
      theBuffer - a ByteBuffer in read mode. Must contain enough capacity for the additional bytes.
      Throws:
      IOException - passthrough from readData(int, ByteBuffer)
    • readData

      protected abstract void readData(int minAmount, ByteBuffer theBuffer) throws IOException
      Read some data from the implementation-defined source into the given data buffer. The buffer is expected to be in write mode. After this call, the buffer must contain minAmount additional bytes.
      Parameters:
      minAmount - caller wants this many additional bytes
      theBuffer - put the bytes in ths buffer. Must have minAmount additional capacity.
      Throws:
      IOException
    • handleRow

      protected void handleRow()
      Handle a row entry after it's read in. Default behavior is to call the registered row handler. Extending classes may override this.
    • handleRecord

      protected void handleRecord()
      Handle a record entry after it's read in. Default behavior is to call the registered record handler. Extending classes may override this.
    • setRowHandler

      public Runnable setRowHandler(@NotNull Runnable handler)
      Set the handler that will handle a row binary store row entry after it has been parsed. This handler will be called by TableReader.readEntry() or TableReader.readRow().
      Parameters:
      handler - the replacement row handler
      Returns:
      the previous handler
    • setRecordHandler

      public Runnable setRecordHandler(@NotNull Runnable handler)
      Set the handler that will handle a binary store record entry after it has been parsed. This handler will be called by TableReader.readEntry()
      NB: The record handler will never be called in a V1 reader.
      Parameters:
      handler - the replacement record handler
      Returns:
      the previous handler