Class HexOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
fc.io.HexOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Writes supplied bytes in hex/ascii form. Useful for hex dumps and
debugging. Each write(..) method call is independent of previous
invokations and prints data seperately from previous lines. This stream
can also optionally print in other bases instead of hex.
In addition to it's streamy goodness, this class also provided some misc.
static utility functions such as toHex(int)
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Be careful with this call, if the underlying stream is say, System.out, then calling this method will close System.outvoidflush()static voidUnit Test:voidsetAutoFlush(boolean val) Sets this stream to flush it's contents after every write statement.voidsetBase(int base) Shows output in the specified base (instead of the default hex).voidshowLineNumbers(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 final StringtoHex(byte[] buf) Utility method to convert a byte buffer to a hexadecimal string.voidwrite(byte[] buf) voidwrite(byte[] buf, int off, int len) voidwrite(int b) Methods inherited from class OutputStream
nullOutputStream
-
Constructor Details
-
HexOutputStream
Constructs a new HexOutputStream with a default width of 16 hex numbers (and corresponding ascii values) per line.- Parameters:
out- the underlying outputstream to send the data to
-
HexOutputStream
Constructs a new HexOutputStream with the specified column width.- Parameters:
out- the underlying outputstream to send the data towidth- the number of hex numbers to print per line
-
-
Method Details
-
close
Be careful with this call, if the underlying stream is say, System.out, then calling this method will close System.out- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterOutputStream
-
write
- Overrides:
writein classFilterOutputStream
-
write
- Overrides:
writein classFilterOutputStream
-
write
- Overrides:
writein classFilterOutputStream
-
setAutoFlush
Sets this stream to flush it's contents after every write statement. By default, this is true. -
showLineNumbers
true/false enables or disables showing line numbers at the beginning of each line, if there is more than 1 line in the output. The line number prefix is a running counter of the number of bytes displayed so far. This counter is reset after at the beginning of each write method call. -
setBase
Shows output in the specified base (instead of the default hex). To redundantly set to hex, specify 16. To show decimal, specify 10.- Parameters:
base- the base to show each byte in. Must be between 2 and 36 (inclusive)- Throws:
IllegalArgumentException- if the specified base is not between [2, 36]
-
toHex
-
main
-