Size64
, java.io.Closeable
, java.lang.AutoCloseable
public class ByteArrayDiskQueue extends java.lang.Object implements java.io.Closeable, Size64
This class is a wrapper around a ByteDiskQueue
that provides methods to
enqueue and dequeue() byte arrays. Like a
ByteDiskQueue
, and instance of this class has a suspend()
method that releases
the file handle without deleting the dump file. The file handle is reinitialized lazily (which
implies that a certain number of enqueue(byte[])
/dequeue()
calls can be performed on a suspended
class without actually reopening the dump file).
Similarly to a ByteDiskQueue
, you can freeze()
and then
reopen a ByteArrayDiskQueue
.
ByteDiskQueue
Modifier | Constructor | Description |
---|---|---|
protected |
ByteArrayDiskQueue(ByteDiskQueue byteDiskQueue) |
Modifier and Type | Method | Description |
---|---|---|
ByteArrayList |
buffer() |
Returns the current buffer of this byte-array disk queue.
|
void |
clear() |
Clears this queue.
|
void |
close() |
Closes this queue.
|
static ByteArrayDiskQueue |
createFromFile(long size,
java.io.File file,
int bufferSize,
boolean direct) |
Creates a new disk-based queue of byte arrays using an existing file.
|
static ByteArrayDiskQueue |
createNew(java.io.File file,
int bufferSize,
boolean direct) |
Creates a new disk-based queue of byte arrays.
|
void |
dequeue() |
Dequeues a byte array from the queue in FIFO fashion.
|
void |
enlargeBuffer(int newBufferSize) |
Enlarge the buffer of this queue to a given size.
|
void |
enqueue(byte[] array) |
Enqueues a byte array to this queue.
|
void |
enqueue(byte[] array,
int offset,
int length) |
Enqueues a byte-array fragment to this queue.
|
void |
freeze() |
Freezes this queue.
|
boolean |
isEmpty() |
|
int |
size() |
Deprecated.
|
long |
size64() |
|
void |
suspend() |
Suspends this queue.
|
void |
trim() |
Trims this queue.
|
protected ByteArrayDiskQueue(ByteDiskQueue byteDiskQueue)
public static ByteArrayDiskQueue createNew(java.io.File file, int bufferSize, boolean direct) throws java.io.IOException
file
- the file that will be used to dump the queue on disk.bufferSize
- the number of items in the circular buffer (will be possibly decreased so to be a power of two).direct
- whether the ByteBuffer
used by this queue should be allocated directly.java.io.IOException
ByteDiskQueue.createNew(File, int, boolean)
public static ByteArrayDiskQueue createFromFile(long size, java.io.File file, int bufferSize, boolean direct) throws java.io.IOException
Note that you have to supply the correct number of byte arrays contained in the dump file of
the underlying ByteDiskQueue
. Failure to do so will cause unpredictable behaviour.
size
- the number of byte arrays contained in file
.file
- the file that will be used to dump the queue on disk.bufferSize
- the number of items in the circular buffer (will be possibly decreased so to be a power of two).direct
- whether the ByteBuffer
used by this queue should be allocated directly.java.io.IOException
ByteDiskQueue.createFromFile(File, int, boolean)
public void enqueue(byte[] array) throws java.io.IOException
array
- the array to be enqueued.java.io.IOException
public void enqueue(byte[] array, int offset, int length) throws java.io.IOException
array
- a byte array.offset
- the first valid byte in array
.length
- the number of valid elements in array
.java.io.IOException
public void dequeue() throws java.io.IOException
java.io.IOException
public ByteArrayList buffer()
dequeue()
has filled this buffer with the result of the dequeue operation.
Only the first k bytes, where k is the number returned by dequeue()
, are valid.public boolean isEmpty()
public void close() throws java.io.IOException
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
java.io.IOException
ByteDiskQueue.close()
public void freeze() throws java.io.IOException
java.io.IOException
ByteDiskQueue.freeze()
public void clear()
ByteDiskQueue.clear()
public void trim() throws java.io.IOException
java.io.IOException
ByteDiskQueue.trim()
public void suspend() throws java.io.IOException
java.io.IOException
ByteDiskQueue.suspend()
public void enlargeBuffer(int newBufferSize)
newBufferSize
- the required buffer size.ByteDiskQueue.enlargeBuffer(int)