org.mycore.datamodel.ifs
Class MCRBlockingInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.BufferedInputStream
              extended by org.mycore.datamodel.ifs.MCRBlockingInputStream
All Implemented Interfaces:
Closeable

public class MCRBlockingInputStream
extends BufferedInputStream

This class implements a special kind of BufferedInputStream that blocks invocations of the read method until the number of bytes that were requested are fully read from the underlying InputStream. In contrast, BufferedInputStream does NOT block when the requested number of bytes is not available yet.

Version:
$Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
Author:
Frank Lützenkirchen
See Also:
BufferedInputStream

Field Summary
 
Fields inherited from class java.io.BufferedInputStream
buf, count, marklimit, markpos, pos
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MCRBlockingInputStream(InputStream in)
          Constructs a new MCRBlockingInputStream, using the default buffer size of BufferedInputStreams.
MCRBlockingInputStream(InputStream in, int size)
          Constructs a new MCRBlockingInputStream that uses the given buffer size.
 
Method Summary
 int read(byte[] buf, int off, int len)
          Reads 'len' bytes from the underlying input stream and writes the bytes that have been read to the buffer 'buf', starting at offset 'off' in the buffer byte array.
 
Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MCRBlockingInputStream

public MCRBlockingInputStream(InputStream in)
Constructs a new MCRBlockingInputStream, using the default buffer size of BufferedInputStreams.

Parameters:
in - the InputStream to read data from

MCRBlockingInputStream

public MCRBlockingInputStream(InputStream in,
                              int size)
Constructs a new MCRBlockingInputStream that uses the given buffer size.

Parameters:
in - the InputStream to read data from
size - the size of the read buffer to be used
Method Detail

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException
Reads 'len' bytes from the underlying input stream and writes the bytes that have been read to the buffer 'buf', starting at offset 'off' in the buffer byte array. In contrast to BufferedInputStream.read(), this method blocks the read request until 'len' bytes have been read completely or the end of the input stream is reached.

Overrides:
read in class BufferedInputStream
Returns:
the number of bytes read. If the end of the input stream is not reached yet, this is always the same as the number of bytes requested in the 'len' parameter.
Throws:
IOException