public final class HexInputStream extends InputStream
When a hex input stream is closed, its source will be closed as well.
Constructor and Description |
---|
HexInputStream(Reader source)
Creates a new hex input stream.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close() |
static byte[] |
decode(CharSequence hex)
Converts a hex representation into a byte array.
|
static byte[] |
decode(CharSequence hex,
int start,
int end)
Converts a hex representation into a byte array.
|
int |
read() |
int |
read(byte[] b,
int off,
int len) |
static Optional<byte[]> |
tryDecode(CharSequence hex)
Attempts to converts a hex representation into a byte array.
|
static Optional<byte[]> |
tryDecode(CharSequence hex,
int start,
int end)
Attempts to converts a hex representation into a byte array.
|
mark, markSupported, read, reset, skip
public HexInputStream(Reader source)
source
- The reader that forms the source of the hex characters.NullPointerException
- If the given reader is null
.public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
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 static byte[] decode(CharSequence hex)
hex
- The character sequence with the hex representation to convert.NullPointerException
- If the given character sequence is null
.IllegalArgumentException
- If the given character sequence does not contain a valid hex representation.public static byte[] decode(CharSequence hex, int start, int end)
hex
- The character sequence with the hex representation to convert.start
- The start index of the character sequence of the hex representation to convert, inclusive.end
- The end index of the character sequence of the hex representation to convert, exclusive.NullPointerException
- If the given character sequence is null
.IndexOutOfBoundsException
- If the given start index is negative,
the given end index is larger than the given character sequence's length,
or the given start index is larger than the given end index.IllegalArgumentException
- If the given character sequence does not contain a valid hex representation.public static Optional<byte[]> tryDecode(CharSequence hex)
hex
- The character sequence with the hex representation to convert.Optional
with the bytes from the given hex representation,
or Optional.empty()
if the character sequence is null
or does not contain a valid hex representation.IndexOutOfBoundsException
- If the given start index is negative,
the given end index is larger than the given character sequence's length,
or the given start index is larger than the given end index.public static Optional<byte[]> tryDecode(CharSequence hex, int start, int end)
hex
- The character sequence with the hex representation to convert.start
- The start index of the character sequence of the hex representation to convert, inclusive.end
- The end index of the character sequence of the hex representation to convert, exclusive.Optional
with the bytes from the given hex representation,
or Optional.empty()
if the character sequence is null
or does not contain a valid hex representation.IndexOutOfBoundsException
- If the given start index is negative,
the given end index is larger than the given character sequence's length,
or the given start index is larger than the given end index.Copyright © 2020–2024. All rights reserved.