org.jwall.log.io
Class SequentialFileInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.jwall.log.io.SequentialFileInputStream
All Implemented Interfaces:
Closeable

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.

Author:
Christian Bockermann <chris@jwall.org>

Constructor Summary
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)
           
 
Method Summary
 int available()
           
static void main(String[] args)
           
 boolean markSupported()
           
 boolean matchesSequence(File f)
           
 int read()
           This read method is basically a read of the current open file.
 
Methods inherited from class java.io.InputStream
close, mark, read, read, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequentialFileInputStream

public SequentialFileInputStream(File file)
                          throws IOException
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
    ...
 
The trailing digits may as well be time-stamps or the like. The files are read in order of their last-modification-time.

Parameters:
file - The initial file.
Throws:
IOException

SequentialFileInputStream

public 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.

Parameters:
file - The initial file to start with.
removeAfterRead - Whether the old files should be removed or not.
Throws:
IOException

SequentialFileInputStream

public SequentialFileInputStream(File file,
                                 String pattern,
                                 boolean removeAfterRead)
                          throws IOException
Throws:
IOException
Method Detail

matchesSequence

public boolean matchesSequence(File f)

read

public 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.

Specified by:
read in class InputStream
Throws:
IOException
See Also:
InputStream.read()

markSupported

public boolean markSupported()
Overrides:
markSupported in class InputStream
See Also:
InputStream.markSupported()

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Throws:
IOException
See Also:
InputStream.available()

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception


Copyright © 2012 jwall.org. All Rights Reserved.