Package org.apache.commons.vfs2.util
Class MonitorInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.BufferedInputStream
org.apache.commons.vfs2.util.MonitorInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
An InputStream that provides buffering and end-of-stream monitoring.
-
Field Summary
Fields inherited from class java.io.BufferedInputStream
buf, marklimit, markpos, pos
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a MonitorInputStream from the passed InputStream.MonitorInputStream
(InputStream in, int bufferSize) Constructs a MonitorInputStream from the passed InputStream and with the specified buffer size. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns 0 if the stream is at EOF, else the underlying inputStream will be queried.void
close()
Closes this input stream and releases any system resources associated with the stream.protected void
This method exists in order to allow overriding whether to actually close the underlying stream (VFS-805).long
getCount()
Gets the number of bytes read by this input stream.protected void
onClose()
Called after the stream has been closed.int
read()
Reads a character.int
read
(byte[] buffer, int offset, int length) Reads bytes from this input stream.Methods inherited from class java.io.BufferedInputStream
mark, markSupported, reset, skip
Methods inherited from class java.io.FilterInputStream
read
-
Constructor Details
-
MonitorInputStream
Constructs a MonitorInputStream from the passed InputStream.- Parameters:
in
- The input stream to wrap.
-
MonitorInputStream
Constructs a MonitorInputStream from the passed InputStream and with the specified buffer size.- Parameters:
in
- The input stream to wrap.bufferSize
- The buffer size to use.- Since:
- 2.4
-
-
Method Details
-
available
Returns 0 if the stream is at EOF, else the underlying inputStream will be queried.- Overrides:
available
in classBufferedInputStream
- Returns:
- The number of bytes that are available.
- Throws:
IOException
- if an error occurs.- Since:
- 2.0
-
close
Closes this input stream and releases any system resources associated with the stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classBufferedInputStream
- Throws:
IOException
- if an error occurs.
-
closeSuper
This method exists in order to allow overriding whether to actually close the underlying stream (VFS-805). There are cases where closing that stream will consume any amount of remaining data. In such cases closing a different entity instead (such as an HttpResponse) may be more appropriate.- Throws:
IOException
- if an IO error occurs.
-
getCount
Gets the number of bytes read by this input stream.- Returns:
- The number of bytes read by this input stream.
-
onClose
Called after the stream has been closed. This implementation does nothing.- Throws:
IOException
- if an error occurs.
-
read
Reads a character.- Overrides:
read
in classBufferedInputStream
- Returns:
- The character that was read as an integer.
- Throws:
IOException
- if an IO error occurs.
-
read
Reads bytes from this input stream.- Overrides:
read
in classBufferedInputStream
- Parameters:
buffer
- A byte array in which to place the characters read.offset
- The offset at which to start reading.length
- The maximum number of bytes to read.- Returns:
- The number of bytes read.
- Throws:
IOException
- if an IO error occurs.
-