ikrs.io
Class StopMarkInputStream

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

public class StopMarkInputStream
extends java.io.InputStream

The StopMarkInputStream is an input stream wrapper class that reads bytes from the underlying inputstream until a given stop-mark (byte sequence) is detected or EOF is reached. Closing the StopMarkInputStream will have no effect to the underlying stream.


Constructor Summary
StopMarkInputStream(java.io.InputStream in, byte[] stopMark)
          Constructs a new StopMarkInputStream with the given underlying stream and stop mark.
 
Method Summary
 int available()
           
 void close()
           
 boolean continueStream()
          The continueStream() method resets the stream once the stop mark was reached.
protected  boolean continueStream(boolean overrideEOI)
          The continueStream() method resets the stream once the stop mark was reached.
 boolean eoiReached()
          This method just tells if the underlying input stream reached EOI.
 boolean isClosed()
          This method just tells if this input stream was already closed..
static void main(java.lang.String[] argv)
           
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 void reset()
           
 long skip(long n)
           
 boolean stopMarkReached()
          This method just tells if this input stream already reached the stop mark; reaching the stop mark implies reaching EOF.
 java.lang.String toString()
           
 
Methods inherited from class java.io.InputStream
read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StopMarkInputStream

public StopMarkInputStream(java.io.InputStream in,
                           byte[] stopMark)
                    throws java.lang.NullPointerException,
                           java.lang.IllegalArgumentException
Constructs a new StopMarkInputStream with the given underlying stream and stop mark.

Parameters:
in - The input stream to read from (must not be null).
stopMark - The stop mark byte sequence (must not be null but may be empty).
Throws:
java.lang.NullPointerException
java.lang.IllegalArgumentException
Method Detail

continueStream

public boolean continueStream()
The continueStream() method resets the stream once the stop mark was reached. This means that the current buffer will be cleared, the stop mark bytes are skipped and more bytes can be read from the underlying read (unless EOI was reached). Actually this method is meant for the use of nested StopMarkInputStreams; once the underlying stream reached its stop mark (equals EOI) the stream can be reset for reading more bytes. Note: this method just calls the protected method continueStream( true ).

Returns:
true if - and only if - EOI was not yet reached. Hint: true does not mean that EOI will not be reached on the next read() call.

continueStream

protected boolean continueStream(boolean overrideEOI)
The continueStream() method resets the stream once the stop mark was reached. This means that the current buffer will be cleared, the stop mark bytes are skipped and more bytes can be read from the underlying read. Unless EOI was reached - OR overrideEOI is set to true. Actually this method is meant for the use of nested StopMarkInputStreams; once the underlying stream reached its stop mark (equals EOI) the stream can be reset for reading more bytes.

Parameters:
overrideEOI - If set to true the next read() call will try to read one more byte from the underlying stream.
Returns:
true if EOI was not yet reached OR overrideOI is set to true. Hint: true does not mean that EOI will not be reached on the next read() call.

isClosed

public boolean isClosed()
This method just tells if this input stream was already closed..


stopMarkReached

public boolean stopMarkReached()
This method just tells if this input stream already reached the stop mark; reaching the stop mark implies reaching EOF.


eoiReached

public boolean eoiReached()
This method just tells if the underlying input stream reached EOI.


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

read

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

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

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