public class HexInputStream extends InputStream
InputStream
assuming that data is little
endian, hexidecimal text, converts that text to bytes, and makes those bytes available through
its interface. The most common usage of this class will involve passing it to the constructor of
another InputStream
. For instance: ObjectInputStream ois = new ObjectInputStream(new GZIPInputStream(new HexInputStream( new FileInputStream(fileName))));
HexOutputStream
Constructor and Description |
---|
HexInputStream(InputStream i)
Initializes this stream with another input stream.
|
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.
|
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 the next byte of data from the input stream.
|
int |
read(byte[] b)
This method has the same effect as
read(b, 0, b.length) . |
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes of data from another input stream into an array of bytes. |
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. |
public HexInputStream(InputStream i)
i
- The input stream from which yet-to-be-converted input should be received.public 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
IOException
public int read(byte[] b) throws IOException
read(b, 0, b.length)
.read
in class InputStream
b
- A buffer in which the converted input is stored.IOException
public int read(byte[] b, int off, int len) throws IOException
len
bytes of data from another input stream into an array of bytes.
An attempt is made to read as many as len
bytes, but a smaller number may be
read, possibly zero. The number of bytes actually read is returned as an integer. b
is null
, a NullPointerException
is thrown. off
is negative, or len
is negative, or off+len
is
greater than the length of the array b
, then an
IndexOutOfBoundsException
is thrown. len
is zero, then no bytes are read and 0 is returned; otherwise, there is an
attempt to read at least one byte. If no byte is available because the stream is at end of
file, the value -1 is returned; otherwise, at least one byte is read and stored into
b
. b[off]
, the next one into
b[off+1]
, and so on. The number of bytes read is, at most, equal to
len
. Let k be the number of bytes actually read; these bytes will be
stored in elements b[off]
through b[off+k-1]
, leaving elements
b[off+k]
through b[off+len-1]
unaffected. b[0]
through b[off-1]
and elements
b[off+len]
through b[b.length-1]
are unaffected. IOException
is thrown. In particular, an IOException
is thrown if
the input stream has been closed.read
in class InputStream
b
- A buffer into which the converted input is stored.off
- The offset in the buffer at which to begin writing.len
- The amount of bytes to be received and written into the buffer.IOException
public 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 InputStream
n
- The number of bytes to be skipped.IOException
public int available() throws IOException
available
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public 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
argument 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 InputStream
readlimit
- The maximum limit of bytes that can be read before the mark position becomes
invalid.public void reset() throws IOException
mark
method was last
called on this input stream.reset
in class InputStream
IOException
public boolean markSupported()
mark
and reset
are supported is an invariant property of the
provided input stream instance.markSupported
in class InputStream
true
iff the provided input stream instance supports the
mark
and reset
methods.Copyright © 2016. All rights reserved.