public class RawInputStream
extends java.io.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(java.io.File file)
Constructs a RawInputStream which provides data from a file. 
 | 
RawInputStream(java.io.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(java.lang.String filename)
Constructs a RawInputStream which provides data from a file. 
 | 
RawInputStream(java.lang.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. | 
java.io.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. 
 | 
java.lang.String | 
readString(int length)
Reads a C-style null terminated byte sequence from the stream, as a
 standard String. 
 | 
java.lang.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. 
 | 
java.lang.String | 
toString()
Returns a string representation of this object. 
 | 
public RawInputStream(byte[] buf,
                      long offset,
                      long length)
               throws java.io.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)java.io.IOException - if an I/O error occurspublic RawInputStream(byte[] buf)
               throws java.io.IOException
buf - the byte array to retrieve data fromjava.io.IOException - if an I/O error occurspublic RawInputStream(java.lang.String filename,
                      long offset,
                      long length)
               throws java.io.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)java.io.IOException - if an I/O error occurspublic RawInputStream(java.lang.String filename)
               throws java.io.IOException
filename - the fully qualified path of the file to retrieve data fromjava.io.IOException - if an I/O error occurspublic RawInputStream(java.io.File file)
               throws java.io.IOException
file - the file to retrieve data fromjava.io.IOException - if an I/O error occurspublic RawInputStream(java.io.File file,
                      long offset,
                      long length)
               throws java.io.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)java.io.IOException - if an I/O error occurspublic RawInputStream(RawInputStream ris) throws java.io.IOException
ris - the RawInputStream to retrieve data fromjava.io.IOException - if an I/O error occurspublic RawInputStream(RawInputStream ris, long offset, long length) throws java.io.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)java.io.IOException - if an I/O error occurspublic long getLength()
public byte[] toByteArray(int max)
                   throws java.io.IOException
max - the maximum number of returned bytes; if negative, there is no
            limitjava.io.IOException - if an I/O error occurspublic byte[] toByteArray()
                   throws java.io.IOException
java.io.IOException - if an I/O error occurspublic int read()
         throws java.io.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 java.io.InputStream-1 if the end of the
         stream is reachedjava.io.IOException - if an I/O error occurspublic long skip(long n)
          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.skip in class java.io.InputStreamn - the number of bytes to be skippedjava.io.IOException - if an I/O error occurspublic int available()
              throws java.io.IOException
available in class java.io.InputStreamjava.io.IOException - if an I/O error occurspublic void close()
           throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOException - 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 java.io.InputStreamreadlimit - the maximum limit of bytes that can be read before the mark
            position becomes invalidInputStream.reset()public void reset()
           throws java.io.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 java.io.InputStreamjava.io.IOException - 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 java.io.InputStreamtrue if this true type supports the mark and reset
         method; false otherwiseInputStream.mark(int), 
InputStream.reset()public long getPosition()
public java.io.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 + 1java.lang.IllegalArgumentException - if start < 0public int readU8()
           throws java.io.IOException
java.io.IOException - if the end of stream has been reached, or if an I/O error
             occurspublic int readU16()
            throws java.io.IOException
java.io.IOException - if the end of stream has been reached, or if an I/O error
             occurspublic long readU32()
             throws java.io.IOException
java.io.IOException - if the end of stream has been reached, or if an I/O error
             occurspublic long readU64()
             throws java.io.IOException
java.io.IOException - if the end of stream has been reached, or if an I/O error
             occurspublic byte[] readBytes(int length)
                 throws java.io.IOException
length - the number of bytes to readjava.io.IOException - if the end of stream has been reached, or if an I/O error
             occurspublic java.lang.String readString(int length)
                            throws java.io.IOException
length - the length of the C-style string in bytes, which may include
            any number of terminating null ('\0') charactersjava.io.IOException - if the end of stream has been reached, or if an I/O error
             occurspublic java.lang.String readStringUnicode(int length)
                                   throws java.io.IOException
length - the length of the C-style string in bytes, which may include
            any number of terminating null ('\0') charactersjava.io.IOException - if the end of stream has been reached, or if an I/O error
             occurspublic java.lang.String toString()
toString in class java.lang.Objectprotected void finalize()
                 throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable - the Exception raised by this methodCopyright © 2023. All Rights Reserved.