ikrs.io
Class MultiStopMarkInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by ikrs.io.MultiStopMarkInputStream
All Implemented Interfaces:
java.io.Closeable

public class MultiStopMarkInputStream
extends java.io.InputStream

The MultiStopMarkInputStream is an enhancement of the normal StopMarkInputStream class, it supports a whole set of stop marks to be passed, which split the underlying inputstream into tokens each time one of the stop mark as found. The order or the passed stop marks is the order the input sequence will be matched for the marks.


Constructor Summary
MultiStopMarkInputStream(java.io.InputStream in, java.util.List<byte[]> stopMarks)
          Creates a new MultiStopMarkInputStream and creates a copy of the passed stop mark list.
MultiStopMarkInputStream(java.io.InputStream in, java.util.List<byte[]> stopMarks, boolean copyList)
          Creates a new MultiStopMarkInputStream and creates a copy of the passed stop mark list if the 'copyList' param is set to true.
 
Method Summary
 int available()
           
 void close()
           
 boolean continueStream()
          When a stop mark was reached the underlying stream might not have reached EOI yet.
 boolean eoiReached()
          This method tell whether the underlying stream reached EOI.
 byte[] getReachedStopMark()
          If a stop mark was reached this method tell which one it was.
 int getReachedStopMarkIndex()
          If a stop mark was hit this method return its index in the initially passed list.
 boolean isClosed()
          Determines whether this input stream was already closed.
static void main(java.lang.String[] argv)
          Just for testing
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 void reset()
           
 long skip(long n)
           
 boolean stopMarkReached()
          This method determines if a stop mark was reached.
 
Methods inherited from class java.io.InputStream
read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiStopMarkInputStream

public MultiStopMarkInputStream(java.io.InputStream in,
                                java.util.List<byte[]> stopMarks)
                         throws java.lang.NullPointerException
Creates a new MultiStopMarkInputStream and creates a copy of the passed stop mark list.

Parameters:
in - The underlying input stream.
stopMarks - A non-empty and non-null list of stop marks to be used. The order of the marks is the final detection order, beginning at index 0.
Throws:
java.lang.NullPointerException - If 'in' is null or 'stopMarks' is null or the list contains any null items.

MultiStopMarkInputStream

public MultiStopMarkInputStream(java.io.InputStream in,
                                java.util.List<byte[]> stopMarks,
                                boolean copyList)
                         throws java.lang.NullPointerException
Creates a new MultiStopMarkInputStream and creates a copy of the passed stop mark list if the 'copyList' param is set to true. If the stop mark list is empty the stream will behave like a normal InputStream.

Parameters:
in - The underlying input stream.
stopMarks - A non-empty and non-null list of stop marks to be used. The order of the marks is the final detection order, beginning at index 0.
copyList - If set to true the constructor will create an internal copy of the passed list.
Throws:
java.lang.NullPointerException - If 'in' is null or 'stopMarks' is null or the list contains any null items.
Method Detail

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException
Overrides:
available in class java.io.InputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException

mark

public void mark(int readlimit)
Overrides:
mark in class java.io.InputStream

markSupported

public boolean markSupported()
Overrides:
markSupported in class java.io.InputStream

reset

public void reset()
           throws java.io.IOException
Overrides:
reset in class java.io.InputStream
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException
Overrides:
skip in class java.io.InputStream
Throws:
java.io.IOException

isClosed

public boolean isClosed()
Determines whether this input stream was already closed.

Returns:
true If the close() method was already called.

continueStream

public boolean continueStream()
When a stop mark was reached the underlying stream might not have reached EOI yet. If you call this method the internal stopMarkReached flaf will be cleared and more bytes can be read until the next stop mark or EOI is reached.

Returns:
true If the stream was not yet closed or EOI was not yet reached; true indicates that it is ready to read more bytes, but it's no promise that the next read() call will not hit EOI.

stopMarkReached

public boolean stopMarkReached()
This method determines if a stop mark was reached. If a stop mark was reached the read() method will return -1 until the continueStream() method was called. This will clear the internal stopMarkReached flag.

Returns:
true If any of the passed stop marks was hit.

getReachedStopMarkIndex

public int getReachedStopMarkIndex()
If a stop mark was hit this method return its index in the initially passed list. Otherwise -1 is returned. Calling continueStream() will cause this method to return -1 again.

Returns:
The index of the reached stop mark (index in the list), IF one was hit.
See Also:
stopMarkReached()

getReachedStopMark

public byte[] getReachedStopMark()
If a stop mark was reached this method tell which one it was.

Returns:
The stop mark itself, if one was reached; null otherwise.x

eoiReached

public boolean eoiReached()
This method tell whether the underlying stream reached EOI. Note: if the read() method returns -1 it does not nesesarily indicate that EOI was reached. The stream might also have hit a stop mark.

Returns:
true If the underlying input stream reached EOI and no more bytes are available.

main

public static void main(java.lang.String[] argv)
Just for testing