import sun.misc.*; import java.io.*; import java.awt.*; public class HexDumpDecoder extends CharacterDecoder { protected int bytesPerAtom() { return 1; } protected int bytesPerLine() { return 16; } protected void decodeAtom(InputStream in, OutputStream out, int l) throws IOException { int c = in.read(); while (c == ' ') c = in.read(); char c1 = (char) c; char c2 = (char) in.read(); // read the space int i1 = Character.digit(c1, 16); int i2 = Character.digit(c2, 16); in.read(); byte b = (byte) (i1*16 + i2); out.write(b); } protected int decodeLinePrefix(InputStream in, OutputStream out) throws IOException { // for (int i = 0; i < 6; i++) in.read(); return (bytesPerLine()); } public static void main(String[] args) { try { FileDialog fd = new FileDialog(new Frame(), "Select the file to decode"); fd.show(); File theFile = new File(fd.getFile()); HexDumpDecoder hd = new HexDumpDecoder(); FileInputStream fis = new FileInputStream(theFile); FileOutputStream fos = new FileOutputStream(theFile + ".unhd"); hd.decodeBuffer(fis, fos); } catch (IOException e) { System.err.println(e); } } /** * decodeLineSuffix in this decoder simply finds the [newLine] and * positions us past it. */ protected void decodeLineSuffix(InputStream inStream, OutputStream outStream) throws java.io.IOException { int c; while (true) { c = inStream.read(); if (c == -1) { throw new CEStreamExhausted(); } if ((c == '\n') || (c == '\r')) { break; } } } }