public class RawInputStream extends InputStream
RawInputStream class is an InputStream which can provide
raw byte data from several underlying sources, including a byte array,
a partial section of a byte array, a file, a partial section of a file,
another RawInputStream, or a partial section of another RawInputStream.| Constructor and Description |
|---|
RawInputStream(byte[] buf)
Constructs a RawInputStream which provides data from a byte array.
|
RawInputStream(byte[] buf,
long offset,
long length)
Constructs a RawInputStream which provides data from a byte array.
|
RawInputStream(File file)
Constructs a RawInputStream which provides data from a file.
|
RawInputStream(File file,
long offset,
long length)
Constructs a RawInputStream which provides data from a file.
|
RawInputStream(RawInputStream ris)
Constructs a RawInputStream which provides data from another RawInputStream.
|
RawInputStream(RawInputStream ris,
long offset,
long length)
Constructs a RawInputStream which provides data from another RawInputStream.
|
RawInputStream(String filename)
Constructs a RawInputStream which provides data from a file.
|
RawInputStream(String filename,
long offset,
long length)
Constructs a RawInputStream which provides data from a file.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
void |
close()
Closes this input stream and releases any system resources associated
with the stream.
|
protected void |
finalize()
Finalizes this object and frees its resources (called by the JVM
garbage collector when this object is discarded).
|
long |
getLength()
Gets the length of the raw data in bytes.
|
long |
getPosition()
Return the current position in the InputStream, as an
offset from the beginning of the underlying InputStream.
|
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. |
InputStream |
newStream(long start,
long end)
Return a new InputStream representing a subset of the data
from this InputStream, starting at
start (inclusive)
up to end (exclusive). |
int |
read()
Reads the next byte of data from the input stream.
|
byte[] |
readBytes(int length)
Reads a given number of bytes from the stream.
|
String |
readString(int length)
Reads a C-style null terminated byte sequence from the stream,
as a standard String.
|
String |
readStringUnicode(int length)
Reads a C-style null terminated Unicode byte sequence from the stream,
as a standard String.
|
int |
readU16()
Reads an unsigned 16-bit value (little-endian ordered) from the stream.
|
long |
readU32()
Reads an unsigned 32-bit value (little-endian ordered) from the stream.
|
long |
readU64()
Reads a 64-bit value (little-endian ordered) from the stream.
|
int |
readU8()
Reads an unsigned 8-bit value from the stream.
|
void |
reset()
Repositions this stream to the position at the time the
mark method was last called on this input stream. |
long |
skip(long n)
Skips over and discards
n bytes of data from this input
stream. |
byte[] |
toByteArray()
Gets the raw data as a byte array, starting at the current position
and ending at the end of the stream.
|
byte[] |
toByteArray(int max)
Gets the raw data as a byte array, starting at the current position
and ending either at the end of the stream, or after the given
maximum number of bytes, whichever comes first.
|
String |
toString()
Returns a string representation of this object.
|
read, readpublic RawInputStream(byte[] buf,
long offset,
long length)
throws IOException
buf - the byte array to retrieve data fromoffset - the offset within the array to start getting data atlength - the length of the partial stream to create (in bytes)IOException - if an I/O error occurspublic RawInputStream(byte[] buf)
throws IOException
buf - the byte array to retrieve data fromIOException - if an I/O error occurspublic RawInputStream(String filename, long offset, long length) throws IOException
filename - the fully qualified path of the file to retrieve data fromoffset - the offset within the file to start getting data atlength - the length of the partial stream to create (in bytes)IOException - if an I/O error occurspublic RawInputStream(String filename) throws IOException
filename - the fully qualified path of the file to retrieve data fromIOException - if an I/O error occurspublic RawInputStream(File file) throws IOException
file - the file to retrieve data fromIOException - if an I/O error occurspublic RawInputStream(File file, long offset, long length) throws IOException
file - the file to retrieve data fromoffset - the offset within the file to start getting data atlength - the length of the partial stream to create (in bytes)IOException - if an I/O error occurspublic RawInputStream(RawInputStream ris) throws IOException
ris - the RawInputStream to retrieve data fromIOException - if an I/O error occurspublic RawInputStream(RawInputStream ris, long offset, long length) throws IOException
ris - the RawInputStream to retrieve data fromoffset - the offset from the current position at which the
new stream will beginlength - the length of the partial stream to create (in bytes)IOException - if an I/O error occurspublic long getLength()
public byte[] toByteArray(int max)
throws IOException
max - the maximum number of returned bytes;
if negative, there is no limitIOException - if an I/O error occurspublic byte[] toByteArray()
throws IOException
IOException - if an I/O error occurspublic int read()
throws IOException
int in the range 0 to
255. If no byte is available because the end of the stream
has been reached, the value -1 is returned. This method
blocks until input data is available, the end of the stream is detected,
or an exception is thrown.read in class InputStream-1 if the end of the
stream is reachedIOException - if an I/O error occurspublic long skip(long n)
throws 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.skip in class InputStreamn - the number of bytes to be skippedIOException - if an I/O error occurspublic int available()
throws IOException
available in class InputStreamIOException - if an I/O error occurspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOException - if an I/O error occurspublic void mark(int readlimit)
reset method repositions this stream at the last marked
position so that subsequent reads re-read the same bytes.
The readlimit arguments tells this input stream to
allow that many bytes to be read before the mark position gets
invalidated.
The general contract of mark is that, if the method
markSupported returns true, the stream somehow
remembers all the bytes read after the call to mark and
stands ready to supply those same bytes again if and whenever the method
reset is called. However, the stream is not required to
remember any data at all if more than readlimit bytes are
read from the stream before reset is called.
mark in class InputStreamreadlimit - the maximum limit of bytes that can be read before
the mark position becomes invalidInputStream.reset()public void reset()
throws IOException
mark method was last called on this input stream.
The general contract of reset is:
markSupported returns
true, then:
mark has not been called since
the stream was created, or the number of bytes read from the stream
since mark was last called is larger than the argument
to mark at that last call, then an
IOException might be thrown.
IOException is not thrown, then the
stream is reset to a state such that all the bytes read since the
most recent call to mark (or since the start of the
file, if mark has not been called) will be resupplied
to subsequent callers of the read method, followed by
any bytes that otherwise would have been the next input data as of
the time of the call to reset. markSupported returns
false, then:
reset may throw an
IOException.
IOException is not thrown, then the stream
is reset to a fixed state that depends on the particular type of the
input stream and how it was created. The bytes that will be supplied
to subsequent callers of the read method depend on the
particular type of the input stream. reset in class InputStreamIOException - if this stream has not been marked or if the
mark has been invalidatedInputStream.mark(int),
IOExceptionpublic boolean markSupported()
mark and
reset methods.markSupported in class InputStreamtrue if this true type supports the mark and reset
method; false otherwiseInputStream.mark(int),
InputStream.reset()public long getPosition()
public InputStream newStream(long start, long end)
start (inclusive)
up to end (exclusive). start must be
non-negative. If end is -1, the new stream ends
at the same place as this stream.start - the starting position, relative to current positionend - the ending position + 1IllegalArgumentException - if start < 0public int readU8()
throws IOException
IOException - if the end of stream has been reached,
or if an I/O error occurspublic int readU16()
throws IOException
IOException - if the end of stream has been reached,
or if an I/O error occurspublic long readU32()
throws IOException
IOException - if the end of stream has been reached,
or if an I/O error occurspublic long readU64()
throws IOException
IOException - if the end of stream has been reached,
or if an I/O error occurspublic byte[] readBytes(int length)
throws IOException
length - the number of bytes to readIOException - if the end of stream has been reached,
or if an I/O error occurspublic String readString(int length) throws IOException
length - the length of the C-style string in bytes, which may
include any number of terminating null ('\0') charactersIOException - if the end of stream has been reached,
or if an I/O error occurspublic String readStringUnicode(int length) throws IOException
length - the length of the C-style string in bytes, which may
include any number of terminating null ('\0') charactersIOException - if the end of stream has been reached,
or if an I/O error occurspublic String toString()
This software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.