mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2025-01-03 10:29:19 +00:00
Migrated code to generate the formatted hex dump into AppleUtil.
This commit is contained in:
parent
4d9aeb9f67
commit
1691df0387
@ -21,9 +21,6 @@ package com.webcodepro.applecommander.storage;
|
||||
|
||||
import com.webcodepro.applecommander.util.AppleUtil;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Filter the given file data to be the appropriate length.
|
||||
* <p>
|
||||
@ -31,16 +28,6 @@ import java.io.PrintWriter;
|
||||
* @author: Rob Greene
|
||||
*/
|
||||
public class HexDumpFileFilter implements FileFilter {
|
||||
/**
|
||||
* This is the number of bytes to display per line.
|
||||
*/
|
||||
private static final int BYTES_PER_LINE = 16;
|
||||
/**
|
||||
* This is the ASCII space character as used by the Apple ][.
|
||||
* The high bit is off.
|
||||
*/
|
||||
private static final int APPLE_SPACE = 0x20;
|
||||
|
||||
/**
|
||||
* Constructor for BinaryFileFilter.
|
||||
*/
|
||||
@ -49,54 +36,11 @@ public class HexDumpFileFilter implements FileFilter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the hex dump format. This is in the general form of:<br>
|
||||
* MMMMMM: HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH AAAAAAAA AAAAAAAA<br>
|
||||
* Where MMMMMM = memory address, HH = hex byte, and
|
||||
* A = ASCII character.
|
||||
* Create the hex dump format.
|
||||
* @see com.webcodepro.applecommander.storage.FileFilter#filter(byte[])
|
||||
*/
|
||||
public byte[] filter(FileEntry fileEntry) {
|
||||
byte[] fileData = fileEntry.getFileData();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
PrintWriter printer = new PrintWriter(output);
|
||||
printer.print(" Offset ");
|
||||
printer.print("Hex Data ");
|
||||
printer.println("Characters");
|
||||
printer.print("======= ");
|
||||
printer.print("================================================ ");
|
||||
printer.println("=================");
|
||||
for (int offset=0; offset<fileData.length; offset+= BYTES_PER_LINE) {
|
||||
printer.print("$");
|
||||
printer.print(AppleUtil.getFormatted3ByteAddress(offset));
|
||||
printer.print(" ");
|
||||
for (int b=0; b<BYTES_PER_LINE; b++) {
|
||||
if (b == BYTES_PER_LINE / 2) printer.print(' ');
|
||||
int index = offset+b;
|
||||
printer.print( (index < fileData.length) ?
|
||||
AppleUtil.getFormattedByte(fileData[index]) : "..");
|
||||
printer.print(' ');
|
||||
}
|
||||
printer.print(' ');
|
||||
for (int a=0; a<BYTES_PER_LINE; a++) {
|
||||
if (a == BYTES_PER_LINE / 2) printer.print(' ');
|
||||
int index = offset+a;
|
||||
if (index < fileData.length) {
|
||||
char ch = (char) (fileData[index] & 0x7f);
|
||||
if ((byte)ch >= (byte)APPLE_SPACE) {
|
||||
printer.print(ch);
|
||||
} else {
|
||||
printer.print('.');
|
||||
}
|
||||
} else {
|
||||
printer.print(' ');
|
||||
}
|
||||
}
|
||||
printer.println();
|
||||
}
|
||||
printer.println("** END **");
|
||||
printer.flush();
|
||||
printer.close();
|
||||
return output.toByteArray();
|
||||
return AppleUtil.getHexDump(fileEntry.getFileData()).getBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user