public final class HexOutputStream extends FilterOutputStream
In addition to it's streamy goodness, this class also provided some misc.
static utility functions such as toHex(int)
Constructor and Description |
---|
HexOutputStream(OutputStream out)
Constructs a new HexOutputStream with a default width of
16 hex numbers (and corresponding ascii values) per line.
|
HexOutputStream(OutputStream out,
int width)
Constructs a new HexOutputStream with the specified column width.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Be careful with this call, if the underlying stream
is say, System.out, then calling this method will
close System.out
|
void |
flush() |
static void |
main(String[] args)
Unit Test:
|
void |
setAutoFlush(boolean val)
Sets this stream to flush it's contents after every
write statement.
|
void |
setBase(int base)
Shows output in the specified base (instead of the default hex).
|
void |
showLineNumbers(boolean val)
true/false enables or disables showing line numbers at
the beginning of each line, if there is more than 1 line in
the output.
|
static String |
toHex(byte[] buf)
Utility method to convert a byte buffer to a hexadecimal string.
|
void |
write(byte[] buf) |
void |
write(byte[] buf,
int off,
int len) |
void |
write(int b) |
public HexOutputStream(OutputStream out)
out
- the underlying outputstream to send the data topublic HexOutputStream(OutputStream out, int width)
out
- the underlying outputstream to send the data towidth
- the number of hex numbers to print per linepublic void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class FilterOutputStream
public void flush()
flush
in interface Flushable
flush
in class FilterOutputStream
public void write(int b)
write
in class FilterOutputStream
public void write(byte[] buf)
write
in class FilterOutputStream
public void write(byte[] buf, int off, int len)
write
in class FilterOutputStream
public void setAutoFlush(boolean val)
public void showLineNumbers(boolean val)
public void setBase(int base)
base
- the base to show each byte in. Must be between
2 and 36 (inclusive)IllegalArgumentException
- if the specified base is not between [2, 36]public static final String toHex(byte[] buf)