org.archive.io
Class DiskByteQueue

java.lang.Object
  extended by org.archive.io.DiskByteQueue
All Implemented Interfaces:
java.io.Serializable

public class DiskByteQueue
extends java.lang.Object
implements java.io.Serializable

FIFO byte queue, using disk space as needed. TODO: add maximum size? Flips between two backing files: as soon as reading head reaches end of one, and is about to start at the front of the other, the writing tail flips to a new file. The current write-target file (tail) has a file extension ".qout", the current read file (head) has a file extension ".qin".

Author:
Gordon Mohr
See Also:
Serialized Form

Nested Class Summary
 class DiskByteQueue.FlipFileInputStream
          An input stream that supports the DiskBackedByteQueue, by always reading from the current inFile, and triggering a "flip" when one inFile is exhausted.
(package private)  class DiskByteQueue.FlipFileOutputStream
          An output stream that supports the DiskBackedByteQueue, by always appending to the current outFile.
 
Field Summary
(package private)  java.lang.String backingFilenamePrefix
           
(package private)  DiskByteQueue.FlipFileInputStream headStream
           
(package private)  java.io.File inFile
           
(package private)  java.io.File outFile
           
(package private)  long rememberedPosition
           
(package private)  DiskByteQueue.FlipFileOutputStream tailStream
           
(package private)  java.io.File tempDir
           
 
Constructor Summary
DiskByteQueue(java.io.File tempDir, java.lang.String backingFilenamePrefix, boolean reuse)
          Create a new BiskBackedByteQueue in the given directory with given filename prefix
 
Method Summary
 void close()
           
 void connect()
           
 void discard()
          frees all streams/files associated with this object
 void disconnect()
           
(package private)  void flip()
          flip the current outFile to the inFile role, make new outFile
 java.io.InputStream getHeadStream()
           
 java.io.InputStream getReadAllInputStream()
          Returns an input stream that covers the entire queue.
 java.io.OutputStream getTailStream()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tempDir

java.io.File tempDir

backingFilenamePrefix

java.lang.String backingFilenamePrefix

inFile

java.io.File inFile

outFile

java.io.File outFile

headStream

transient DiskByteQueue.FlipFileInputStream headStream

rememberedPosition

long rememberedPosition

tailStream

transient DiskByteQueue.FlipFileOutputStream tailStream
Constructor Detail

DiskByteQueue

public DiskByteQueue(java.io.File tempDir,
                     java.lang.String backingFilenamePrefix,
                     boolean reuse)
Create a new BiskBackedByteQueue in the given directory with given filename prefix

Parameters:
tempDir -
backingFilenamePrefix -
reuse - whether to reuse any prexisting backing files
Method Detail

getHeadStream

public java.io.InputStream getHeadStream()
                                  throws java.io.IOException
Returns:
The stream to read from this byte queue
Throws:
java.io.IOException

getTailStream

public java.io.OutputStream getTailStream()
                                   throws java.io.FileNotFoundException
Returns:
The stream to write to this byte queue
Throws:
java.io.FileNotFoundException

flip

void flip()
    throws java.io.IOException
flip the current outFile to the inFile role, make new outFile

Throws:
java.io.IOException

getReadAllInputStream

public java.io.InputStream getReadAllInputStream()
                                          throws java.io.IOException
Returns an input stream that covers the entire queue. It only allows read access. Reading from it will not affect the queue in any way. It is not safe to add or remove items to the queue while using this stream.

Returns:
an input stream that covers the entire queue
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

discard

public void discard()
             throws java.io.IOException
frees all streams/files associated with this object

Throws:
java.io.IOException

disconnect

public void disconnect()
                throws java.io.IOException
Throws:
java.io.IOException

connect

public void connect()
             throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2003-2005 Internet Archive. All Rights Reserved.