Package com.twelvemonkeys.io
Class SubStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.twelvemonkeys.io.SubStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
An
InputStream
reading up to a specified number of bytes from an
underlying stream.-
Field Summary
FieldsFields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionSubStream
(InputStream stream, long length) Creates aSubStream
of the givenstream
. -
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
Marks this stream as closed.private long
findMaxLen
(long length) Finds the maximum number of bytes we can read or skip, from this stream.void
mark
(int readLimit) int
read()
int
read
(byte[] bytes) int
read
(byte[] bytes, int off, int len) void
reset()
long
skip
(long length) Methods inherited from class java.io.FilterInputStream
markSupported
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
bytesLeft
private long bytesLeft -
markLimit
private int markLimit
-
-
Constructor Details
-
SubStream
Creates aSubStream
of the givenstream
.- Parameters:
stream
- the underlying input streamlength
- maximum number of bytes to read from this stream
-
-
Method Details
-
close
Marks this stream as closed. This implementation does not close the underlying stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classFilterInputStream
- Throws:
IOException
-
mark
public void mark(int readLimit) - Overrides:
mark
in classFilterInputStream
-
reset
- Overrides:
reset
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classFilterInputStream
- Throws:
IOException
-
findMaxLen
private long findMaxLen(long length) Finds the maximum number of bytes we can read or skip, from this stream.- Parameters:
length
- the requested length- Returns:
- the maximum number of bytes to read
-