Package com.saperion.common.io
Class TempFileByteBuffer
- java.lang.Object
-
- com.saperion.common.io.TempFileByteBuffer
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
ReadOnceTempFileByteBuffer
public class TempFileByteBuffer extends java.lang.Object implements java.io.Closeable
A buffer for bytes that keeps a certain amount of bytes in memory before switching to a temporary file.
-
-
Field Summary
Fields Modifier and Type Field Description static int
MINIMUM_BUFFER_SIZE
Minimum size for in-memory buffer.
-
Constructor Summary
Constructors Constructor Description TempFileByteBuffer(int inMemoryBytes)
TempFileByteBuffer(int inMemoryBytes, java.io.File tempFileDirectory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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()
java.io.File
getDirectory()
java.io.InputStream
getInputStream()
int
getMaxInMemoryBytes()
long
getSize()
boolean
inMemory()
-
-
-
Field Detail
-
MINIMUM_BUFFER_SIZE
public static final int MINIMUM_BUFFER_SIZE
Minimum size for in-memory buffer.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TempFileByteBuffer
public TempFileByteBuffer(int inMemoryBytes)
- Parameters:
inMemoryBytes
- number of bytes to keep in memory before using a temp file
-
TempFileByteBuffer
public TempFileByteBuffer(int inMemoryBytes, java.io.File tempFileDirectory)
- Parameters:
inMemoryBytes
- number of bytes to keep in memory before using a temp filetempFileDirectory
- directory to store temporary files in
-
-
Method Detail
-
append
public void append(byte[] bytes) throws java.io.IOException
Appends bytes to the end of the buffer.- Parameters:
bytes
- bytes to append- Throws:
java.io.IOException
- IO exception when appending the bytes
-
append
public void append(byte[] bytes, int offset, int length) throws java.io.IOException
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:
java.io.IOException
-
append
public void append(int b) throws java.io.IOException
Appends one byte to the end of the buffer.- Parameters:
b
- byte to append- Throws:
java.io.IOException
- IO exception when appending the bytes
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
- Returns:
- an input stream to read the bytes stored in this buffer
- Throws:
java.io.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 java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
getMaxInMemoryBytes
public int getMaxInMemoryBytes()
-
getDirectory
public java.io.File getDirectory()
-
-