Class TempFileByteBuffer

java.lang.Object
com.saperion.common.io.TempFileByteBuffer
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
ReadOnceTempFileByteBuffer

public class TempFileByteBuffer extends Object implements Closeable
A buffer for bytes that keeps a certain amount of bytes in memory before switching to a temporary file.
  • Field Details

    • MINIMUM_BUFFER_SIZE

      public static final int MINIMUM_BUFFER_SIZE
      Minimum size for in-memory buffer.
      See Also:
  • Constructor Details

    • TempFileByteBuffer

      public TempFileByteBuffer(int inMemoryBytes)
      Parameters:
      inMemoryBytes - number of bytes to keep in memory before using a temp file
    • TempFileByteBuffer

      public TempFileByteBuffer(int inMemoryBytes, File tempFileDirectory)
      Parameters:
      inMemoryBytes - number of bytes to keep in memory before using a temp file
      tempFileDirectory - directory to store temporary files in
  • Method Details

    • append

      public void append(byte[] bytes) throws IOException
      Appends bytes to the end of the buffer.
      Parameters:
      bytes - bytes to append
      Throws:
      IOException - IO exception when appending the bytes
    • append

      public void append(byte[] bytes, int offset, int length) throws IOException
      Appends length bytes to the end of the buffer skipping data before position offset in the provided byte-array.
      Parameters:
      bytes - bytes to append
      offset - position to start reading from
      length - amount of bytes to write
      Throws:
      IOException
    • append

      public void append(int b) throws IOException
      Appends one byte to the end of the buffer.
      Parameters:
      b - byte to append
      Throws:
      IOException - IO exception when appending the bytes
    • getInputStream

      public InputStream getInputStream() throws IOException
      Returns:
      an input stream to read the bytes stored in this buffer
      Throws:
      IOException - IO exception when opering the stream
    • getSize

      public long getSize()
      Returns:
      current size of the buffer
    • inMemory

      public boolean inMemory()
      Returns:
      true if all the data stored in this buffer is kept in RAM
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • getMaxInMemoryBytes

      public int getMaxInMemoryBytes()
    • getDirectory

      public File getDirectory()