Package com.aoindustries.io
Class FifoFile
- java.lang.Object
-
- com.aoindustries.io.FifoFile
-
public class FifoFile extends Object
AFifoFileallows code to read and write to an on-disk managed FIFO. Objects of this class provideInputStreamandOutputStreamimplementations that may be used by any number of concurrent threads. If using this class to access a single file from multiple instances ofFifoFile, whether in a single JVM or different JVMs, due to limitations of the underlyingRandomAccessFile, 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 ofFifoFile.This class is best used for persistence or management of large FIFO data sets.
- Author:
- AO Industries, Inc.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()Flushes all updates to this file to the underlying storage device.intgetBlockSize()longgetFileLength()protected longgetFirstIndex()Gets the data index of the next value that will be read.FifoFileInputStreamgetInputStream()longgetLength()Gets the number of bytes currently contained by the FIFO.longgetMaximumFifoLength()FifoFileOutputStreamgetOutputStream()voidreset()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 Detail
-
FifoFile
public FifoFile(String filename, long maxFifoLength) throws IOException
- Throws:
IOException
-
FifoFile
public FifoFile(File file, long maxFifoLength) throws IOException
- Throws:
IOException
-
-
Method Detail
-
getInputStream
public FifoFileInputStream getInputStream()
-
getOutputStream
public FifoFileOutputStream getOutputStream()
-
getMaximumFifoLength
public long getMaximumFifoLength()
-
getFileLength
public long getFileLength()
-
getBlockSize
public int getBlockSize()
-
reset
public void reset() throws IOExceptionResets thisFifoFileto contain no contents and start writing at the beginning of the file.- Throws:
IOException
-
close
public void close() throws IOException- Throws:
IOException
-
getFirstIndex
protected long getFirstIndex() throws IOExceptionGets the data index of the next value that will be read.- Throws:
IOException
-
setFirstIndex
protected void setFirstIndex(long index) throws IOExceptionSets the data index of the next value that will be read.- Throws:
IOException
-
getLength
public long getLength() throws IOExceptionGets the number of bytes currently contained by the FIFO.- Throws:
IOException
-
setLength
protected void setLength(long length) throws IOExceptionSets the number of bytes currently contained by the FIFO.- Throws:
IOException
-
flush
public void flush() throws IOExceptionFlushes all updates to this file to the underlying storage device. This is performed byRandomAccessFile.getChannel().force(true).- Throws:
IOException- See Also:
FifoFileOutputStream.flush()
-
-