net.sf.mmm.util.io.impl
Class ProcessableDetectorInputStream.WrapperInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by net.sf.mmm.util.io.impl.ProcessableDetectorInputStream.WrapperInputStream
All Implemented Interfaces:
Closeable, DetectorStreamProcessor
Enclosing class:
ProcessableDetectorInputStream

protected class ProcessableDetectorInputStream.WrapperInputStream
extends InputStream
implements DetectorStreamProcessor

This inner class is the actual wrapper stream.

See Also:
ProcessableDetectorInputStream.getStream()

Field Summary
private  InputStream delegate
          The delegate adapted by this wrapper.
private  boolean endOfStream
          true if end of detection-stream, false otherwise.
private  DetectorStreamBuffer targetBuffer
          The destination buffer (end of chain)
 
Constructor Summary
ProcessableDetectorInputStream.WrapperInputStream(InputStream inputStream)
          The constructor.
 
Method Summary
 void close()
          
protected  void fill(int requiredBufferLength)
          This method tries to ensure that the internal buffer has at least the given number of bytes available.
 void process(DetectorStreamBuffer buffer, Map<String,Object> metadata, boolean eos)
          This method performs the actual detection and optionally manipulates the data.
 int read()
          
 int read(byte[] buffer, int offset, int length)
          
 long skip(long n)
          
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delegate

private final InputStream delegate
The delegate adapted by this wrapper.


targetBuffer

private DetectorStreamBuffer targetBuffer
The destination buffer (end of chain)


endOfStream

private boolean endOfStream
true if end of detection-stream, false otherwise.

Constructor Detail

ProcessableDetectorInputStream.WrapperInputStream

public ProcessableDetectorInputStream.WrapperInputStream(InputStream inputStream)
The constructor.

Parameters:
inputStream - is the InputStream to adapt.
Method Detail

close

public void close()
           throws IOException

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

read

public int read()
         throws IOException

Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws IOException

Overrides:
read in class InputStream
Throws:
IOException

skip

public long skip(long n)
          throws IOException

Overrides:
skip in class InputStream
Throws:
IOException

fill

protected void fill(int requiredBufferLength)
             throws IOException
This method tries to ensure that the internal buffer has at least the given number of bytes available. If less bytes are available, the buffer is filled up accordingly using the underlying stream.
ATTENTION:
If EOS is hit, the requested buffer size can NOT be ensured.

Parameters:
requiredBufferLength - is the desired number of bytes for the buffer.
Throws:
IOException - if an I/O error occurred.

process

public void process(DetectorStreamBuffer buffer,
                    Map<String,Object> metadata,
                    boolean eos)
             throws IOException
This method performs the actual detection and optionally manipulates the data. All this happens via the given buffer that provides access to read buffered parts of the stream. As streams are typically larger pieces of data, this method will be called repetitive in order to process the entire stream.
ATTENTION:
A legal implementation of this interface has to consume data from the given buffer whenever it is invoked. To ensure your implementation can always make an appropriate decision it may have to ensure a specific lookahead.

Specified by:
process in interface DetectorStreamProcessor
Parameters:
buffer - allows you to read parts of the streamed data as well as to manipulate the data.
metadata - is the Map with the meta-data.
eos - - true if the end of the stream has been reached and the given buffer has to be
Throws:
IOException - in case of an Input/Output error. Should only be used internally.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.