home *** CD-ROM | disk | FTP | other *** search
- package sun.misc;
-
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.PrintStream;
-
- public class HexDumpEncoder extends CharacterEncoder {
- private int offset;
- private int thisLineLength;
- private int currentByte;
- private byte[] thisLine = new byte[16];
-
- static void hexDigit(PrintStream var0, byte var1) {
- char var2 = (char)(var1 >> 4 & 15);
- if (var2 > '\t') {
- var2 = (char)(var2 - 10 + 65);
- } else {
- var2 = (char)(var2 + 48);
- }
-
- var0.write(var2);
- var2 = (char)(var1 & 15);
- if (var2 > '\t') {
- var2 = (char)(var2 - 10 + 65);
- } else {
- var2 = (char)(var2 + 48);
- }
-
- var0.write(var2);
- }
-
- protected int bytesPerAtom() {
- return 1;
- }
-
- protected int bytesPerLine() {
- return 16;
- }
-
- protected void encodeBufferPrefix(OutputStream var1) throws IOException {
- this.offset = 0;
- super.encodeBufferPrefix(var1);
- }
-
- protected void encodeLinePrefix(OutputStream var1, int var2) throws IOException {
- hexDigit(super.pStream, (byte)(this.offset >>> 8 & 255));
- hexDigit(super.pStream, (byte)(this.offset & 255));
- super.pStream.print(": ");
- this.currentByte = 0;
- this.thisLineLength = var2;
- }
-
- protected void encodeAtom(OutputStream var1, byte[] var2, int var3, int var4) throws IOException {
- this.thisLine[this.currentByte] = var2[var3];
- hexDigit(super.pStream, var2[var3]);
- super.pStream.print(" ");
- ++this.currentByte;
- if (this.currentByte == 8) {
- super.pStream.print(" ");
- }
-
- }
-
- protected void encodeLineSuffix(OutputStream var1) throws IOException {
- if (this.thisLineLength < 16) {
- for(int var2 = this.thisLineLength; var2 < 16; ++var2) {
- super.pStream.print(" ");
- if (var2 == 7) {
- super.pStream.print(" ");
- }
- }
- }
-
- super.pStream.print(" ");
-
- for(int var3 = 0; var3 < this.thisLineLength; ++var3) {
- if (this.thisLine[var3] >= 32 && this.thisLine[var3] <= 122) {
- super.pStream.write(this.thisLine[var3]);
- } else {
- super.pStream.print(".");
- }
- }
-
- super.pStream.println();
- this.offset += this.thisLineLength;
- }
- }
-