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:
Closeable

public class MagicByteInputStream
extends 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(InputStream pStream, byte[] pMagic)
          Creates a new instance of MagicByteInputStream for the given stream and magic byte(s).
 
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(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
Method Detail

read

public int read()
         throws IOException

Overrides:
read in class FilterInputStream
Throws:
IOException

read

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

Overrides:
read in class FilterInputStream
Throws:
IOException

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Overrides:
close in class FilterInputStream
Throws:
IOException

readMagicByte

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

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


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.