Class DataInputBlock

java.lang.Object
org.docx4j.org.apache.poi.poifs.storage.DataInputBlock

public final class DataInputBlock extends Object
Wraps a byte array and provides simple data input access. Internally, this class maintains a buffer read index, so that for the most part, primitive data can be read in a data-input-stream-like manner.

Note - the calling class should call the available() method to detect end-of-buffer and move to the next data block when the current is exhausted. For optimisation reasons, no error handling is performed in this class. Thus, mistakes in calling code ran may raise ugly exceptions here, like ArrayIndexOutOfBoundsException, etc .

The multi-byte primitive input methods (readUShortLE(), readIntLE() and readLongLE()) have corresponding 'spanning read' methods which (when required) perform a read across the block boundary. These spanning read methods take the previous DataInputBlock as a parameter. Reads of larger amounts of data (into byte array buffers) must be managed by the caller since these could conceivably involve more than two blocks.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final byte[]
    Possibly any size (usually 512K or 64K).
    private int
     
    private int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DataInputBlock(byte[] data, int startOffset)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    void
    readFully(byte[] buf, int off, int len)
    Reads len bytes from this block into the supplied buffer.
    int
    Reads an int which was encoded in little endian format.
    int
    readIntLE(DataInputBlock prevBlock, int prevBlockAvailable)
    Reads an int which spans the end of prevBlock and the start of this block.
    long
    Reads a long which was encoded in little endian format.
    long
    readLongLE(DataInputBlock prevBlock, int prevBlockAvailable)
    Reads a long which spans the end of prevBlock and the start of this block.
    private void
    readSpanning(DataInputBlock prevBlock, int prevBlockAvailable, byte[] buf)
    Reads a small amount of data from across the boundary between two blocks.
    int
     
    int
    Reads a short which was encoded in little endian format.
    int
    Reads a short which spans the end of prevBlock and the start of this block.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _buf

      private final byte[] _buf
      Possibly any size (usually 512K or 64K). Assumed to be at least 8 bytes for all blocks before the end of the stream. The last block in the stream can be any size except zero.
    • _readIndex

      private int _readIndex
    • _maxIndex

      private int _maxIndex
  • Constructor Details

    • DataInputBlock

      DataInputBlock(byte[] data, int startOffset)
  • Method Details

    • available

      public int available()
    • readUByte

      public int readUByte()
    • readUShortLE

      public int readUShortLE()
      Reads a short which was encoded in little endian format.
    • readUShortLE

      public int readUShortLE(DataInputBlock prevBlock)
      Reads a short which spans the end of prevBlock and the start of this block.
    • readIntLE

      public int readIntLE()
      Reads an int which was encoded in little endian format.
    • readIntLE

      public int readIntLE(DataInputBlock prevBlock, int prevBlockAvailable)
      Reads an int which spans the end of prevBlock and the start of this block.
    • readLongLE

      public long readLongLE()
      Reads a long which was encoded in little endian format.
    • readLongLE

      public long readLongLE(DataInputBlock prevBlock, int prevBlockAvailable)
      Reads a long which spans the end of prevBlock and the start of this block.
    • readSpanning

      private void readSpanning(DataInputBlock prevBlock, int prevBlockAvailable, byte[] buf)
      Reads a small amount of data from across the boundary between two blocks. The _readIndex of this (the second) block is updated accordingly. Note- this method (and other code) assumes that the second DataInputBlock always is big enough to complete the read without being exhausted.
    • readFully

      public void readFully(byte[] buf, int off, int len)
      Reads len bytes from this block into the supplied buffer.