summaryrefslogtreecommitdiff
path: root/utils/src/main/java/at/gv
diff options
context:
space:
mode:
Diffstat (limited to 'utils/src/main/java/at/gv')
-rw-r--r--utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java33
1 files changed, 21 insertions, 12 deletions
diff --git a/utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java b/utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java
index 88d49bad..a1b8a00d 100644
--- a/utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java
+++ b/utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java
@@ -32,14 +32,21 @@ public class HexDump {
public static void hexDump(InputStream is, Writer writer) throws IOException {
hexDump(is, writer, 16);
}
+
+ public static void hexDump(InputStream is, Writer writer, int chunkSize) throws IOException {
+ hexDump(is, writer, chunkSize, false);
+ }
- public static void hexDump(InputStream is, Writer writer, int chunkSize) throws IOException {
+ public static void hexDump(InputStream is, Writer writer, int chunkSize, boolean plain) throws IOException {
byte[] chunk = new byte[chunkSize];
long adr = 0;
for (int l; (l = is.read(chunk)) != -1;) {
+
+ if (!plain) {
+ writer.append(String.format("[%06x]", adr));
+ }
- writer.append(String.format("[%06x]", adr));
for (int i = 0; i < l; i++) {
if (i % 8 == 0) {
writer.append(" ");
@@ -53,16 +60,18 @@ public class HexDump {
for (int i = 0; i < (chunkSize - l); i++) {
writer.append(" ");
}
-
- for (int i = 0; i < l; i++) {
- if (i % 8 == 0) {
- writer.append(" ");
- }
- if (chunk[i] > 31 && chunk[i] < 127) {
- writer.append((char) chunk[i]);
- } else {
- writer.append(".");
- }
+
+ if (!plain) {
+ for (int i = 0; i < l; i++) {
+ if (i % 8 == 0) {
+ writer.append(" ");
+ }
+ if (chunk[i] > 31 && chunk[i] < 127) {
+ writer.append((char) chunk[i]);
+ } else {
+ writer.append(".");
+ }
+ }
}
writer.append("\n");