com.sibvisions.util.io
Class MagicByteInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by com.sibvisions.util.io.MagicByteInputStream
All Implemented Interfaces:
java.io.Closeable

public class MagicByteInputStream
extends java.io.FilterInputStream

The MagicByteInputStream is an InputStream wrapper which reads some magic bytes from the end of the stream. It will read the byte sequence until found.


Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MagicByteInputStream(java.io.InputStream pStream, byte[] pMagic)
          Creates a new instance of MagicByteInputStream for the given stream and magic byte(s).
MagicByteInputStream(java.io.InputStream pStream, byte[] pMagic, boolean pAutoEOF)
          Creates a new instance of MagicByteInputStream for the given stream and optional sets EOF if magic byte was detected.
 
Method Summary
 void close()
          
 int read()
          
 int read(byte[] pContent, int pOffset, int pLength)
          
 void readMagicByte()
          Reads until the magic byte was found.
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MagicByteInputStream

public MagicByteInputStream(java.io.InputStream pStream,
                            byte[] pMagic)
Creates a new instance of MagicByteInputStream for the given stream and magic byte(s).

Parameters:
pStream - the wrapped stream
pMagic - the magic byte sequence

MagicByteInputStream

public MagicByteInputStream(java.io.InputStream pStream,
                            byte[] pMagic,
                            boolean pAutoEOF)
Creates a new instance of MagicByteInputStream for the given stream and optional sets EOF if magic byte was detected.

Parameters:
pStream - the wrapped stream
pMagic - the magic byte sequence
pAutoEOF - true to set EOF if magic byte was found
Method Detail

read

public int read()
         throws java.io.IOException

Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

read

public int read(byte[] pContent,
                int pOffset,
                int pLength)
         throws java.io.IOException

Overrides:
read in class java.io.FilterInputStream
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.FilterInputStream
Throws:
java.io.IOException

readMagicByte

public void readMagicByte()
                   throws java.io.IOException
Reads until the magic byte was found.

Throws:
java.io.IOException - if reading failed or EOF reached and magic byte wasn't found


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.