|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.util.HexDump
public class HexDump
Do a "hexdump" of binary data. Seems like there always comes a time when one needs to dump the contents of some binary data. This class allows one to do that, it dumps output in the following form (up to 16 bytes per line by default):
oooooooo:xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx ................
Where:
offset of
the bytes being dumped.
To use this class, you keep invoking the formatBytes(java.io.PrintWriter, byte[], int, int)
method until you no longer have more bytes to dump. Once you are
done dumping all of your bytes (or whenever you want to force the
output of what's been formatted so far), you invoke the flush(java.io.PrintWriter) method.
By default, this class sets the initial offset to 0 and the initial number of bytes per line to 16.
PrintWriterString,
com.ccg.app.convert.HexDump| Constructor Summary | |
|---|---|
HexDump()
Default object constructor. |
|
| Method Summary | |
|---|---|
static String |
bytesToHexString(byte[] bytes,
int ofs,
int len)
|
void |
clearLine()
Cancel the output of the remaining bytes in the current line. |
void |
flush(PrintWriter pw)
Flush out any "lingering" data. |
void |
formatBytes(PrintWriter pw,
byte[] bytes,
int ofs,
int len)
Add the values of a set of bytes to the hex dump output. |
long |
getOffset()
Get the current offset position. |
static void |
print(PrintWriter pw,
byte b)
Print a single byte in the default hex form. |
void |
setBytesPerLine(int len)
Set the number of bytes to display on each line of output. |
void |
setOffset(long ofs)
Set the offset position. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public HexDump()
bytes per line to 16 and
initializes the starting offset to 0.
formatBytes(java.io.PrintWriter, byte[], int, int)| Method Detail |
|---|
public void setBytesPerLine(int len)
arg1 - Number of bytes to display per line. If set to a value less
than 1, it will be forced to the default value of 16.setOffset(long),
clearLine()
public static void print(PrintWriter pw,
byte b)
pw - Where to display hex valueb - Byte to display
public void formatBytes(PrintWriter pw,
byte[] bytes,
int ofs,
int len)
length (16 by default),
the current output line will then be flushed and
remaining bytes will start on the next line.
This method allows one to specify what portion of the byte array is to be dumped, to dump the entire array, set the 'ofs' to 0 and the 'len' to -1 like:
hd.formatBytes(pw,bytes,0,-1);
pw - Where to dump output as each line is completed.bytes - Array containing bytes to dump. The bytes actually dumped will
depend upon the setting of the 'ofs' and 'len' parameters.ofs - Offset in byte array to start dumping from (must be 0 or
higher - if its greater than or equal to the length of the
array, then nothing will be done).len - How many bytes to display. Set to a negitive value (like -1)
and all of the bytes to the end of the array will be
displayed.flush(java.io.PrintWriter)
public static String bytesToHexString(byte[] bytes,
int ofs,
int len)
public void flush(PrintWriter pw)
formatBytes(java.io.PrintWriter, byte[], int, int) method is invoked, one or more
bytes are added to the next line to be dumped by this
object. Since it is possible (even likely) that a call to formatBytes(java.io.PrintWriter, byte[], int, int) won't come out to exactly one lines worth of
output, it is likely that a portion of a line will "linger"
inside this object. Typically, this is fine and one doesn't want
to worry about this "lingering" affect. There are two exceptions,
however, when one will want to use this method to force the
"lingering" output out:
pw - Where to dump any "lingering" output.formatBytes(java.io.PrintWriter, byte[], int, int)public long getOffset()
formatBytes(java.io.PrintWriter, byte[], int, int). This value is affected by the setOffset(long)
method.
setOffset(long)public void setOffset(long ofs)
Typically, you can let this class keep track of things automatically for you - however, there may be times when you don't do a hex dump of ALL of your bytes (in which case your offset will be out of sync). You can use this method to specify the current offset (position) to bring this object back into sync with your application.
ofs - New offset position in output.getOffset()public void clearLine()
formatBytes(java.io.PrintWriter, byte[], int, int) method is invoked, it is
possible that ASCII output will "linger". Typically one will
invoke the flush(java.io.PrintWriter) method to force this data out, however,
this method can be used instead if one wants to cancel the
"lingering" output (this would be fairly unusual).
This method is always invoked when the setBytesPerLine(int) method is invoked.
setBytesPerLine(int),
flush(java.io.PrintWriter)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||