java.lang.Object
com.aoapps.hodgepodge.io.FifoFile
A
FifoFile allows code to read and write to an on-disk managed FIFO.
Objects of this class provide InputStream and OutputStream
implementations that may be used by any number of concurrent threads. If using this
class to access a single file from multiple instances of FifoFile, whether
in a single JVM or different JVMs, due to limitations of the underlying
RandomAccessFile, only one instance may read and one instance may write.
However, race conditions still exists in this scenario, and it is strongly advised
to access a file through a single instance of FifoFile.
This class is best used for persistence or management of large FIFO data sets.
- Author:
- AO Industries, Inc.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()Flushes all updates to this file to the underlying storage device.intlongprotected longGets the data index of the next value that will be read.longGets the number of bytes currently contained by the FIFO.longvoidreset()Resets thisFifoFileto contain no contents and start writing at the beginning of the file.protected voidsetFirstIndex(long index) Sets the data index of the next value that will be read.protected voidsetLength(long length) Sets the number of bytes currently contained by the FIFO.
-
Constructor Details
-
FifoFile
- Throws:
IOException
-
FifoFile
- Throws:
IOException
-
-
Method Details
-
getInputStream
-
getOutputStream
-
getMaximumFifoLength
public long getMaximumFifoLength() -
getFileLength
public long getFileLength() -
getBlockSize
public int getBlockSize() -
reset
Resets thisFifoFileto contain no contents and start writing at the beginning of the file.- Throws:
IOException
-
close
- Throws:
IOException
-
getFirstIndex
Gets the data index of the next value that will be read.- Throws:
IOException
-
setFirstIndex
Sets the data index of the next value that will be read.- Throws:
IOException
-
getLength
Gets the number of bytes currently contained by the FIFO.- Throws:
IOException
-
setLength
Sets the number of bytes currently contained by the FIFO.- Throws:
IOException
-
flush
Flushes all updates to this file to the underlying storage device. This is performed byRandomAccessFile.getChannel().force(true).- Throws:
IOException- See Also:
-
