| java.lang.Object java.io.InputStream org.geoserver.ows.util.RewindableInputStream
Field Summary | |
final public static int | DEFAULT_XMLDECL_BUFFER_SIZE | protected byte[] | fData Internal buffer of bytes already read from source input stream. | protected int | fEndOffset Position where the end of underlying stream was encountered. | protected InputStream | fInputStream Source input stream we are wrapping with rewindable one. | protected int | fLength Number of read bytes currently stored in fData buffer. | protected int | fMark Offset of the "marked" position in the stream relative to its beginning. | protected boolean | fMayReadChunks | protected int | fOffset | protected int | fStartOffset Position in the stream that to which stream pointer can be reset
with rewind method invocation. |
Constructor Summary | |
public | RewindableInputStream(InputStream is) Creates new RewindableInputStream object with internal
buffer of default size and default value of chunked reading flag (which
is _currently_ true ). | public | RewindableInputStream(InputStream is, boolean chunkedMode) Creates new RewindableInputStream with internal buffer of specified size
and no chunk reading beyound the buffer limits allowed. | public | RewindableInputStream(InputStream is, boolean chunkedMode, int initialSize) Primary constructor that allows to specify all parameters exlicitly
affecting class work (initial size of the internal buffer and
chunk read mode).
Parameters: is - InputStream that needs some reset/rewind functionality. Parameters: chunkedMode - Initial value of fMayReadChunks flag which determineswhether multiple bytes can be read from the underlying stream insingle reading operation or not. |
Method Summary | |
public int | available() Returns the number of bytes that can be read (or skipped over) from this
input stream without blocking by the next caller of a method for this
input stream. | public void | close() Closes underlying byte stream. | public void | disableChunkedMode() More conscious alias for setChunkedMode(false) . | public void | enableChunkedMode() More conscious alias for setChunkedMode(true) . | public void | mark(int howMuch) Sets a mark to the current position in the stream. | public boolean | markSupported() Tells that this stream supports mark/reset capability. | public int | read() Reads next byte from this stream. | public int | read(byte[] b, int off, int len) Reads up to len bytes of data from the input stream into an array of
bytes. | public void | reset() Returns stream pointer to the position previously remembered
using mark method (or to beginning of the stream,
if there were no mark method calls). | public void | rewind() Quickly reset stream pointer to the beginning of the stream or to
position which offset was specified during the last
setStartOffset call. | public void | setChunkedMode(boolean chunkedMode) Allows to change the behavior of the stream regarding chunked reading
at runtime. | public void | setStartOffset(int offset) Sets the position somewhere in the stream to which the stream pointer
will be reset after rewind invocation. | public long | skip(long n) Skips over and discards n bytes of data from this input
stream. |
DEFAULT_XMLDECL_BUFFER_SIZE | final public static int DEFAULT_XMLDECL_BUFFER_SIZE(Code) | | Default buffer size before we've finished with the XMLDecl:
I think the name should be left unchanged to give a hint for
possible use of this class :)
|
fData | protected byte[] fData(Code) | | Internal buffer of bytes already read from source input stream.
Allows to access the same byte more than once.
|
fEndOffset | protected int fEndOffset(Code) | | Position where the end of underlying stream was encountered. Potentially
in RewindableInputStream instance stream's "end" could be
reached more than once, so it is a good thing to know where original
stream ended to avoid IOExceptions .
|
fInputStream | protected InputStream fInputStream(Code) | | Source input stream we are wrapping with rewindable one.
|
fLength | protected int fLength(Code) | | Number of read bytes currently stored in fData buffer.
Size of the buffer itself can be greater than this value, obviously.
|
fMark | protected int fMark(Code) | | Offset of the "marked" position in the stream relative to its beginning.
|
fMayReadChunks | protected boolean fMayReadChunks(Code) | | Tells whether read(byte[], int, int) method
is allowed to read multiple bytes beyond the internal buffer
(true ) or not (true is the default)
|
fOffset | protected int fOffset(Code) | | Offset of the next byte to be read from the stream relative to
the beginning of the stream (and fData array as well)
|
fStartOffset | protected int fStartOffset(Code) | | Position in the stream that to which stream pointer can be reset
with rewind method invocation.
|
RewindableInputStream | public RewindableInputStream(InputStream is)(Code) | | Creates new RewindableInputStream object with internal
buffer of default size and default value of chunked reading flag (which
is _currently_ true ).
Parameters: is - InputStream that needs basic reset/rewind functionality. |
RewindableInputStream | public RewindableInputStream(InputStream is, boolean chunkedMode)(Code) | | Creates new RewindableInputStream with internal buffer of specified size
and no chunk reading beyound the buffer limits allowed.
Parameters: is - InputStream that needs some reset/rewind functionality. Parameters: chunkedMode - See the RewindableInputStream(InputStream,boolean, int) constructor description. |
RewindableInputStream | public RewindableInputStream(InputStream is, boolean chunkedMode, int initialSize)(Code) | | Primary constructor that allows to specify all parameters exlicitly
affecting class work (initial size of the internal buffer and
chunk read mode).
Parameters: is - InputStream that needs some reset/rewind functionality. Parameters: chunkedMode - Initial value of fMayReadChunks flag which determineswhether multiple bytes can be read from the underlying stream insingle reading operation or not. This value can be changed usingsetChunkedMode (or its aliases). For specificpurpose of inferring encoding/charset of XML document typicalusage policy is to disable chunked reads while obtaining XMLdeclaration and then enable it to speed up reading the rest ofdocument. Parameters: initialSize - Initial size of the internal buffer array. |
available | public int available() throws IOException(Code) | | Returns the number of bytes that can be read (or skipped over) from this
input stream without blocking by the next caller of a method for this
input stream. For RewindableInputStream this can be:
-
Number of unread bytes in the
fData buffer, i.e. those
between current position (fOffset) and total bytes quantity in the
buffer (fLength).
-
Result of underlying InputStream's
available call
if there are no unread bytes in the buffer.
-
-1 if end of stream is reached.
the number of bytes that can be read from this input streamwithout blocking. throws: IOException - when an I/O error occurs. |
disableChunkedMode | public void disableChunkedMode()(Code) | | More conscious alias for setChunkedMode(false) . While last
method is a general purpose mutator, code may look a bit more clear if
you use specialized methods to enable/disable chunk read mode.
|
enableChunkedMode | public void enableChunkedMode()(Code) | | More conscious alias for setChunkedMode(true) . While last
method is a general purpose mutator, code may look a bit more clear if
you use specialized methods to enable/disable chunk read mode.
|
mark | public void mark(int howMuch)(Code) | | Sets a mark to the current position in the stream.
Parameters: howMuch - Not used in this implementation I guess. |
markSupported | public boolean markSupported()(Code) | | Tells that this stream supports mark/reset capability.
This one definitely supports it :)
true if this stream instance supports the markand reset methods; false otherwise. |
read | public int read() throws IOException(Code) | | Reads next byte from this stream. This byte is either being read from
underlying InputStream or taken from the internal buffer in case it was
already read at some point before.
Next byte of data or -1 if end of stream is reached. throws: IOException - in case of any I/O errors. |
read | public int read(byte[] b, int off, int len) throws IOException(Code) | | Reads up to len bytes of data from the input stream into an array of
bytes. In its current implementation it cannot return more bytes than
left in the buffer if in "non-chunked" mode
(fMayReadChunks == false ). After reaching the end of
the buffer, each invocation of this method will read exactly 1 byte
then. In "chunked" mode this method may return more than 1
byte, but it doesn't buffer the result.
From the other hand, for the task of reading xml declaration, such
behavior may be desirable, as we probably don't need reset/rewind
functionality after we finished with charset deduction. It is good
idea to call enableChunkedMode after that, in order to
improve perfomance and lessen memoery consumption when reading the rest
of the data.
Total number of bytes actually read or -1 if endof stream has been reached. throws: IOException - when an I/O error occurs while reading data throws: IndexOutOfBoundsException - in case of invalid off ,len and b.length combination |
reset | public void reset()(Code) | | Returns stream pointer to the position previously remembered
using mark method (or to beginning of the stream,
if there were no mark method calls).
|
rewind | public void rewind()(Code) | | Quickly reset stream pointer to the beginning of the stream or to
position which offset was specified during the last
setStartOffset call.
|
setChunkedMode | public void setChunkedMode(boolean chunkedMode)(Code) | | Allows to change the behavior of the stream regarding chunked reading
at runtime. If you allowed chunked reading and then read some data from
the stream, you better forget about reset ting or
rewind ing it after that.
Parameters: chunkedMode - New value for fMayReadChunks . |
setStartOffset | public void setStartOffset(int offset)(Code) | | Sets the position somewhere in the stream to which the stream pointer
will be reset after rewind invocation. By default this
position is the beginning of the stream.
Parameters: offset - New value for "fStartOffset". |
skip | public long skip(long n) throws IOException(Code) | | Skips over and discards 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 . The actual
number of bytes skipped is returned. If n is negative, no
bytes are skipped.
Parameters: n - Number of bytes to be skipped. Number of bytes actually skipped. throws: IOException - if an I/O error occurs. |
|
|