public class SequentialFileInputStream extends InputStream
This class implements an input stream that will read from a sequence of files. It is intended to provide the opposite of a split of files into parts. Each part is read in chronological order.
At the end, the stream waits for new data to be appended to the last file, or a new file to be created that matches the names.
| Constructor and Description |
|---|
SequentialFileInputStream(File file)
Creates a new SequentialInputStream, which will read the specified file and
any subsequent files that match the file's name, possibly and a appended
number, i.e. for the file
/tmp/test.log the stream will read
/tmp/test.log
/tmp/test.log.1
/tmp/test.log.2
... |
SequentialFileInputStream(File file,
boolean removeAfterRead)
This creates a SequentialInputStream which will remove any files that have
completeley been read (i.e. they have been processed until EOF and
another, newer file matching the pattern does exist).
|
SequentialFileInputStream(File file,
String pattern,
boolean removeAfterRead) |
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
protected boolean |
hasNext()
This method checks if there exists a next file in the sequence.
|
static void |
main(String[] args) |
boolean |
markSupported() |
boolean |
matchesSequence(File f) |
protected void |
openNextFile()
This method closes the current file an opens the next file in the sequence.
|
int |
read()
This read method is basically a read of the current open file.
|
public SequentialFileInputStream(File file) throws IOException
/tmp/test.log the stream will read
/tmp/test.log
/tmp/test.log.1
/tmp/test.log.2
...
The trailing digits may as well be time-stamps or the like. The files are
read in order of their last-modification-time.file - The initial file.IOExceptionpublic SequentialFileInputStream(File file, boolean removeAfterRead) throws IOException
This creates a SequentialInputStream which will remove any files that have completeley been read (i.e. they have been processed until EOF and another, newer file matching the pattern does exist).
Whether the old files are to be removed is determined by the removeAfterRead
flag.
file - The initial file to start with.removeAfterRead - Whether the old files should be removed or not.IOExceptionpublic SequentialFileInputStream(File file, String pattern, boolean removeAfterRead) throws IOException
IOExceptionpublic boolean matchesSequence(File f)
protected boolean hasNext()
true if a new file exists, which may indicate that
the current file is finished.protected void openNextFile()
throws IOException
This method closes the current file an opens the next file in the sequence. If no next file exists, this method will block until one has been created.
IOExceptionpublic int read()
throws IOException
This read method is basically a read of the current open file. It will block if there is no more data and no new file exists.
read in class InputStreamIOExceptionInputStream.read()public boolean markSupported()
markSupported in class InputStreamInputStream.markSupported()public int available()
throws IOException
available in class InputStreamIOExceptionInputStream.available()Copyright © 2013 jwall.org. All Rights Reserved.