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 int
Minimum size for in-memory buffer. -
Constructor Summary
ConstructorsConstructorDescriptionTempFileByteBuffer
(int inMemoryBytes) TempFileByteBuffer
(int inMemoryBytes, File tempFileDirectory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(byte[] bytes) Appends bytes to the end of the buffer.void
append
(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.void
append
(int b) Appends one byte to the end of the buffer.void
close()
int
long
getSize()
boolean
inMemory()
-
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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getMaxInMemoryBytes
public int getMaxInMemoryBytes() -
getDirectory
-