Class MCRBlockingInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.BufferedInputStream
org.mycore.common.content.streams.MCRBlockingInputStream
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
MCRHeaderInputStream

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$ $Date$
Author:
Frank Lützenkirchen
See Also:
  • Constructor Details

    • 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 Details

    • 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