Class LinkedByteBuffer

java.lang.Object
ghidra.program.model.pcode.LinkedByteBuffer

public class LinkedByteBuffer extends Object
A byte buffer that is stored as a linked list of pages. Each page holds BUFFER_SIZE bytes. A Position object acts as an iterator over the whole buffer. The buffer can be populated from a stream, either all at once or "as needed" when a Position object iterates past the current cached set of bytes.
  • Field Details

  • Constructor Details

    • LinkedByteBuffer

      public LinkedByteBuffer(int max, int pad, String desc)
  • Method Details

    • close

      public void close() throws IOException
      Close the "as needed" stream, if configure.
      Throws:
      IOException - for problems closing the stream
    • ingestStreamAsNeeded

      public void ingestStreamAsNeeded(InputStream stream, LinkedByteBuffer.Position start) throws IOException
      Set up this buffer so that it reads in pages as needed. The initial page is read immediately. Additional pages are read via readNextPage() through the Position methods.
      Parameters:
      stream - is the stream to read from
      start - will hold the initial buffer
      Throws:
      IOException - for problems reading data from the stream
    • ingestStreamToNextTerminator

      public void ingestStreamToNextTerminator(InputStream stream) throws IOException
      Ingest stream up to the first 0 byte or until maxCount bytes is reached. Store the bytes on the heap in BUFFER_SIZE chunks.
      Parameters:
      stream - is the input
      Throws:
      IOException - for errors reading from the stream
    • ingestStream

      public void ingestStream(InputStream stream) throws IOException
      Read the stream until the end of stream is encountered or until maxCount bytes is reached. Store the bytes on the heap in BUFFER_SIZE chunks.
      Parameters:
      stream - is the input
      Throws:
      IOException - for errors reading from the stream
    • ingestBytes

      public void ingestBytes(byte[] byteArray, int off, int sz) throws IOException
      Ingest bytes directly from a byte array. If these bytes would cause the total number of bytes ingested to exceed the maximum (maxCount) bytes set for this buffer, an exception is thrown. This can be called multiple times to read in different chunks.
      Parameters:
      byteArray - is the array of bytes
      off - is the index of the first byte to ingest
      sz - is the number of bytes to ingest
      Throws:
      IOException - if the max number of bytes to ingest is exceeded
    • pad

      public void pad()
      Add the padValue to the end of the buffer
    • getStartPosition

      public void getStartPosition(LinkedByteBuffer.Position position)