public class DelegatingInputStream
extends java.io.InputStream
| Modifier and Type | Field and Description |
|---|---|
private boolean |
inRead1
Stores if we are in a read method with 1 parameter (avoid double
recording).
|
private boolean |
inRead3
Stores if we are in a read method with 3 parameters (avoid double
recording).
|
private java.lang.String |
recId
Stores the recorder id to aggregate the notifications for.
|
private java.io.InputStream |
stream
Stores the stream to delegate to.
|
private StreamType |
type
Stores the stream type.
|
| Constructor and Description |
|---|
DelegatingInputStream(java.io.InputStream stream,
StreamType type)
Creates a new delegating stream.
|
DelegatingInputStream(java.io.InputStream stream,
StreamType type,
java.lang.String recId)
Creates a new delegating stream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns an estimate of the number of bytes that can be read (or
skipped over) from this input stream without blocking by the next
invocation of a method for this input stream.
|
void |
close()
Closes the stream.
|
static java.io.InputStream |
createFrom(java.io.InputStream is,
java.net.URL url,
java.lang.String recId)
Creates a delegating input stream (if possible) from the given
parameters.
|
void |
mark(int readlimit)
Marks the current position in this input stream.
|
boolean |
markSupported()
Tests if this input stream supports the
mark and
reset methods. |
int |
read()
Reads a byte from a stream.
|
int |
read(byte[] buffer)
Reads bytes into
buffer, at maximum up to the length of the
buffer. |
int |
read(byte[] buffer,
int off,
int len)
Reads at maximum
len bytes into buffer starting
at off. |
void |
reset()
Repositions this stream to the position at the time the
mark method was last called on this input stream. |
long |
skip(long number)
Skips over and discards
n bytes of data from this input
stream. |
private java.io.InputStream stream
private boolean inRead3
private boolean inRead1
private StreamType type
private java.lang.String recId
public DelegatingInputStream(java.io.InputStream stream,
StreamType type)
stream - the stream to delegate the operations totype - the type of the streampublic DelegatingInputStream(java.io.InputStream stream,
StreamType type,
java.lang.String recId)
stream - the stream to delegate the operations totype - the type of the streamrecId - the recorder id to aggregate the notifications forpublic static final java.io.InputStream createFrom(java.io.InputStream is,
java.net.URL url,
java.lang.String recId)
is - the input stream to create the delegating input stream forurl - an URL to take the stream type fromrecId - the recorder id to aggregate the notifications forispublic int available()
throws java.io.IOException
available in class java.io.InputStream0 when it reaches the end of the input stream.java.io.IOException - if an I/O error occurs.public void mark(int readlimit)
reset method repositions this stream at the last marked
position so that subsequent reads re-read the same bytes.mark in class java.io.InputStreamreadlimit - the maximum limit of bytes that can be read before
the mark position becomes invalid.public boolean markSupported()
mark and
reset methods. Whether or not mark and
reset are supported is an invariant property of a
particular input stream instance. The markSupported method
of InputStream returns false.markSupported in class java.io.InputStreamtrue if this stream instance supports the mark
and reset methods; false otherwise.InputStream.mark(int),
InputStream.reset()public void reset()
throws java.io.IOException
mark method was last called on this input stream.reset in class java.io.InputStreamjava.io.IOException - if this stream has not been marked or if the
mark has been invalidated.public long skip(long number)
throws java.io.IOException
n bytes of data from this input
stream. The skip method may, for a variety of reasons, end
up skipping over some smaller number of bytes, possibly 0.
This may result from any of a number of conditions; reaching end of file
before n bytes have been skipped is only one possibility.
The actual number of bytes skipped is returned. If n is
negative, no bytes are skipped.
The skip method of this class creates a
byte array and then repeatedly reads into it until n bytes
have been read or the end of the stream has been reached. Subclasses are
encouraged to provide a more efficient implementation of this method.
For instance, the implementation may depend on the ability to seek.
skip in class java.io.InputStreamnumber - the number of bytes to be skipped.java.io.IOException - if the stream does not support seek,
or if some other I/O error occurs.public int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOException - in case of any I/O error or problempublic int read(byte[] buffer)
throws java.io.IOException
buffer, at maximum up to the length of the
buffer.read in class java.io.InputStreambuffer - the byte buffer to be modifiedjava.io.IOException - in case of I/O reading errorspublic int read(byte[] buffer,
int off,
int len)
throws java.io.IOException
len bytes into buffer starting
at off.read in class java.io.InputStreambuffer - the byte buffer to be modifiedoff - the offset where to start storing byteslen - the maximum number of bytes to be read (less than length of
b)java.io.IOException - in case of I/O reading errorspublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOException - in case of I/O errors