Package org.apache.xmlgraphics.util.io
Class SubInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.xmlgraphics.util.io.SubInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
This class is a FilterInputStream descendant that reads from an underlying InputStream
up to a defined number of bytes or the end of the underlying stream. Closing this InputStream
will not result in the underlying InputStream to be closed, too.
This InputStream can be used to read chunks from a larger file of which the length is known in advance.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
Indicates the number of bytes remaining to be read from the underlying InputStream.private boolean
Indicates whether the underlying stream should be closed when theclose()
method is called.Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionSubInputStream
(InputStream in, long maxLen) Creates a new SubInputStream.SubInputStream
(InputStream in, long maxLen, boolean closeUnderlying) Creates a new SubInputStream. -
Method Summary
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, reset
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
bytesToRead
private long bytesToReadIndicates the number of bytes remaining to be read from the underlying InputStream. -
closeUnderlying
private boolean closeUnderlyingIndicates whether the underlying stream should be closed when theclose()
method is called.
-
-
Constructor Details
-
SubInputStream
Creates a new SubInputStream.- Parameters:
in
- the InputStream to read frommaxLen
- the maximum number of bytes to read from the underlying InputStream until the end-of-file is signalled.closeUnderlying
- true if the underlying stream should be closed when theclose()
method is called.
-
SubInputStream
Creates a new SubInputStream. The underlying stream is not closed, when close() is called.- Parameters:
in
- the InputStream to read frommaxLen
- the maximum number of bytes to read from the underlying InputStream until the end-of-file is signalled.
-
-
Method Details
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classFilterInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterInputStream
- Throws:
IOException
-