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

  1. package sun.misc;
  2.  
  3. import java.io.ByteArrayInputStream;
  4. import java.io.ByteArrayOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.OutputStream;
  8.  
  9. public abstract class CharacterDecoder {
  10.    protected abstract int bytesPerAtom();
  11.  
  12.    protected abstract int bytesPerLine();
  13.  
  14.    protected void decodeBufferPrefix(InputStream var1, OutputStream var2) throws IOException {
  15.    }
  16.  
  17.    protected void decodeBufferSuffix(InputStream var1, OutputStream var2) throws IOException {
  18.    }
  19.  
  20.    protected int decodeLinePrefix(InputStream var1, OutputStream var2) throws IOException {
  21.       return this.bytesPerLine();
  22.    }
  23.  
  24.    protected void decodeLineSuffix(InputStream var1, OutputStream var2) throws IOException {
  25.    }
  26.  
  27.    protected void decodeAtom(InputStream var1, OutputStream var2, int var3) throws IOException {
  28.       throw new CEStreamExhausted();
  29.    }
  30.  
  31.    protected int readFully(InputStream var1, byte[] var2, int var3, int var4) throws IOException {
  32.       for(int var5 = 0; var5 < var4; ++var5) {
  33.          int var6 = var1.read();
  34.          if (var6 == -1) {
  35.             if (var5 == 0) {
  36.                return -1;
  37.             }
  38.  
  39.             return var5;
  40.          }
  41.  
  42.          var2[var5 + var3] = (byte)var6;
  43.       }
  44.  
  45.       return var4;
  46.    }
  47.  
  48.    public void decodeBuffer(InputStream var1, OutputStream var2) throws IOException {
  49.       int var4 = 0;
  50.       this.decodeBufferPrefix(var1, var2);
  51.  
  52.       while(true) {
  53.          try {
  54.             int var5 = this.decodeLinePrefix(var1, var2);
  55.  
  56.             int var3;
  57.             for(var3 = 0; var3 + this.bytesPerAtom() < var5; var3 += this.bytesPerAtom()) {
  58.                this.decodeAtom(var1, var2, this.bytesPerAtom());
  59.                var4 += this.bytesPerAtom();
  60.             }
  61.  
  62.             if (var3 + this.bytesPerAtom() == var5) {
  63.                this.decodeAtom(var1, var2, this.bytesPerAtom());
  64.                var4 += this.bytesPerAtom();
  65.             } else {
  66.                this.decodeAtom(var1, var2, var5 - var3);
  67.                var4 += var5 - var3;
  68.             }
  69.  
  70.             this.decodeLineSuffix(var1, var2);
  71.          } catch (CEStreamExhausted var6) {
  72.             this.decodeBufferSuffix(var1, var2);
  73.             return;
  74.          }
  75.       }
  76.    }
  77.  
  78.    public byte[] decodeBuffer(String var1) throws IOException {
  79.       byte[] var2 = new byte[var1.length()];
  80.       var1.getBytes(0, var1.length(), var2, 0);
  81.       ByteArrayInputStream var3 = new ByteArrayInputStream(var2);
  82.       ByteArrayOutputStream var4 = new ByteArrayOutputStream();
  83.       this.decodeBuffer(var3, var4);
  84.       return var4.toByteArray();
  85.    }
  86.  
  87.    public byte[] decodeBuffer(InputStream var1) throws IOException {
  88.       ByteArrayOutputStream var2 = new ByteArrayOutputStream();
  89.       this.decodeBuffer(var1, var2);
  90.       return var2.toByteArray();
  91.    }
  92. }
  93.