public class JRSwapFile
extends java.lang.Object
Fixed-size blocks are allocated inside the swap file when a caller wants to write data. The caller receives a handle to the allocated area based on which it can read the data or free the area.
The implementation is thread-safe. I/O operations are performed in synchronized blocks, only one thread would do a read or write at one moment.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
JRSwapFile.LongQueue |
static class |
JRSwapFile.SwapHandle |
| Modifier and Type | Field and Description |
|---|---|
protected java.io.RandomAccessFile |
file |
static java.lang.String |
PROPERTY_DELETE_ON_EXIT
Property that instructs whether
deleteOnExit is to be requested
for swap files. |
protected java.io.File |
swapFile |
| Constructor and Description |
|---|
JRSwapFile(java.lang.String directory,
int blockSize,
int minGrowCount)
Creates a swap file.
|
| Modifier and Type | Method and Description |
|---|---|
void |
dispose()
Closes and deletes the swap file.
|
protected void |
finalize() |
void |
free(JRSwapFile.SwapHandle handle)
Frees an allocated area.
|
protected void |
freeBlocks(long[] offsets) |
protected void |
read(byte[] data,
int dataOffset,
int dataLength,
long fileOffset) |
byte[] |
read(JRSwapFile.SwapHandle handle,
boolean free)
Reads all the data from an allocated area.
|
protected long[] |
reserveFreeBlocks(int blockCount) |
java.lang.String |
toString() |
JRSwapFile.SwapHandle |
write(byte[] data)
Allocates an area in the swap file and writes data in it.
|
protected void |
write(byte[] data,
int dataSize,
int dataOffset,
long fileOffset) |
public static final java.lang.String PROPERTY_DELETE_ON_EXIT
deleteOnExit is to be requested
for swap files.
Swap files are explicitly deleted on dispose() and garbage collection.protected final java.io.File swapFile
protected final java.io.RandomAccessFile file
public JRSwapFile(java.lang.String directory,
int blockSize,
int minGrowCount)
directory - the directory where the file should be created.blockSize - the size of the blocks allocated by the swap fileminGrowCount - the minimum number of blocks by which the swap file grows when fullpublic java.lang.String toString()
toString in class java.lang.Objectpublic JRSwapFile.SwapHandle write(byte[] data) throws java.io.IOException
data - the data for which to allocate an area in the filejava.io.IOExceptionprotected void write(byte[] data,
int dataSize,
int dataOffset,
long fileOffset)
throws java.io.IOException
java.io.IOExceptionpublic byte[] read(JRSwapFile.SwapHandle handle, boolean free) throws java.io.IOException
handle - the allocated area handlefree - whether to free the area after readingjava.io.IOExceptionprotected void read(byte[] data,
int dataOffset,
int dataLength,
long fileOffset)
throws java.io.IOException
java.io.IOExceptionpublic void free(JRSwapFile.SwapHandle handle)
handle - the allocated area handlepublic void dispose()
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwableprotected long[] reserveFreeBlocks(int blockCount)
throws java.io.IOException
java.io.IOExceptionprotected void freeBlocks(long[] offsets)
© 2001-2010 Jaspersoft Corporation www.jaspersoft.com