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
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:
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorDescriptionConstructs 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
Modifier and TypeMethodDescriptionint
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.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
MCRBlockingInputStream
Constructs a new MCRBlockingInputStream, using the default buffer size of BufferedInputStreams.- Parameters:
in
- the InputStream to read data from
-
MCRBlockingInputStream
Constructs a new MCRBlockingInputStream that uses the given buffer size.- Parameters:
in
- the InputStream to read data fromsize
- the size of the read buffer to be used
-
-
Method Details
-
read
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 classBufferedInputStream
- 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
-