Package com.saperion.common.io
Class TempFileByteBuffer
java.lang.Object
com.saperion.common.io.TempFileByteBuffer
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
ReadOnceTempFileByteBuffer
A buffer for bytes that keeps a certain amount of bytes in memory before
switching to a temporary file.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMinimum size for in-memory buffer. -
Constructor Summary
ConstructorsConstructorDescriptionTempFileByteBuffer(int inMemoryBytes) TempFileByteBuffer(int inMemoryBytes, File tempFileDirectory) -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(byte[] bytes) Appends bytes to the end of the buffer.voidappend(byte[] bytes, int offset, int length) Appends length bytes to the end of the buffer skipping data before position offset in the provided byte-array.voidappend(int b) Appends one byte to the end of the buffer.voidclose()intlonggetSize()booleaninMemory()
-
Field Details
-
MINIMUM_BUFFER_SIZE
public static final int MINIMUM_BUFFER_SIZEMinimum 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
- Parameters:
inMemoryBytes- number of bytes to keep in memory before using a temp filetempFileDirectory- directory to store temporary files in
-
-
Method Details
-
append
Appends bytes to the end of the buffer.- Parameters:
bytes- bytes to append- Throws:
IOException- IO exception when appending the bytes
-
append
Appends length bytes to the end of the buffer skipping data before position offset in the provided byte-array.- Parameters:
bytes- bytes to appendoffset- position to start reading fromlength- amount of bytes to write- Throws:
IOException
-
append
Appends one byte to the end of the buffer.- Parameters:
b- byte to append- Throws:
IOException- IO exception when appending the bytes
-
getInputStream
- 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
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getMaxInMemoryBytes
public int getMaxInMemoryBytes() -
getDirectory
-