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:
java.io.Closeable,java.lang.AutoCloseable
public class SubInputStream extends java.io.FilterInputStreamThis 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
Fields Modifier and Type Field Description private longbytesToReadIndicates the number of bytes remaining to be read from the underlying InputStream.private booleancloseUnderlyingIndicates whether the underlying stream should be closed when theclose()method is called.
-
Constructor Summary
Constructors Constructor Description SubInputStream(java.io.InputStream in, long maxLen)Creates a new SubInputStream.SubInputStream(java.io.InputStream in, long maxLen, boolean closeUnderlying)Creates a new SubInputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()intread()intread(byte[] b, int off, int len)longskip(long n)
-
-
-
Field Detail
-
bytesToRead
private long bytesToRead
Indicates the number of bytes remaining to be read from the underlying InputStream.
-
closeUnderlying
private boolean closeUnderlying
Indicates whether the underlying stream should be closed when theclose()method is called.
-
-
Constructor Detail
-
SubInputStream
public SubInputStream(java.io.InputStream in, long maxLen, boolean closeUnderlying)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
public SubInputStream(java.io.InputStream in, long maxLen)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 Detail
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException- Overrides:
skipin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterInputStream- Throws:
java.io.IOException
-
-