home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / misc / HexDumpEncoder.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  1.7 KB  |  88 lines

  1. package sun.misc;
  2.  
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.io.PrintStream;
  6.  
  7. public class HexDumpEncoder extends CharacterEncoder {
  8.    private int offset;
  9.    private int thisLineLength;
  10.    private int currentByte;
  11.    private byte[] thisLine = new byte[16];
  12.  
  13.    static void hexDigit(PrintStream var0, byte var1) {
  14.       char var2 = (char)(var1 >> 4 & 15);
  15.       if (var2 > '\t') {
  16.          var2 = (char)(var2 - 10 + 65);
  17.       } else {
  18.          var2 = (char)(var2 + 48);
  19.       }
  20.  
  21.       var0.write(var2);
  22.       var2 = (char)(var1 & 15);
  23.       if (var2 > '\t') {
  24.          var2 = (char)(var2 - 10 + 65);
  25.       } else {
  26.          var2 = (char)(var2 + 48);
  27.       }
  28.  
  29.       var0.write(var2);
  30.    }
  31.  
  32.    protected int bytesPerAtom() {
  33.       return 1;
  34.    }
  35.  
  36.    protected int bytesPerLine() {
  37.       return 16;
  38.    }
  39.  
  40.    protected void encodeBufferPrefix(OutputStream var1) throws IOException {
  41.       this.offset = 0;
  42.       super.encodeBufferPrefix(var1);
  43.    }
  44.  
  45.    protected void encodeLinePrefix(OutputStream var1, int var2) throws IOException {
  46.       hexDigit(super.pStream, (byte)(this.offset >>> 8 & 255));
  47.       hexDigit(super.pStream, (byte)(this.offset & 255));
  48.       super.pStream.print(": ");
  49.       this.currentByte = 0;
  50.       this.thisLineLength = var2;
  51.    }
  52.  
  53.    protected void encodeAtom(OutputStream var1, byte[] var2, int var3, int var4) throws IOException {
  54.       this.thisLine[this.currentByte] = var2[var3];
  55.       hexDigit(super.pStream, var2[var3]);
  56.       super.pStream.print(" ");
  57.       ++this.currentByte;
  58.       if (this.currentByte == 8) {
  59.          super.pStream.print("  ");
  60.       }
  61.  
  62.    }
  63.  
  64.    protected void encodeLineSuffix(OutputStream var1) throws IOException {
  65.       if (this.thisLineLength < 16) {
  66.          for(int var2 = this.thisLineLength; var2 < 16; ++var2) {
  67.             super.pStream.print("   ");
  68.             if (var2 == 7) {
  69.                super.pStream.print("  ");
  70.             }
  71.          }
  72.       }
  73.  
  74.       super.pStream.print(" ");
  75.  
  76.       for(int var3 = 0; var3 < this.thisLineLength; ++var3) {
  77.          if (this.thisLine[var3] >= 32 && this.thisLine[var3] <= 122) {
  78.             super.pStream.write(this.thisLine[var3]);
  79.          } else {
  80.             super.pStream.print(".");
  81.          }
  82.       }
  83.  
  84.       super.pStream.println();
  85.       this.offset += this.thisLineLength;
  86.    }
  87. }
  88.