home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / sun / misc / CharacterDecoder.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.5 KB  |  89 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.             return var5 == 0 ? -1 : var5;
  36.          }
  37.  
  38.          var2[var5 + var3] = (byte)var6;
  39.       }
  40.  
  41.       return var4;
  42.    }
  43.  
  44.    public void decodeBuffer(InputStream var1, OutputStream var2) throws IOException {
  45.       int var4 = 0;
  46.       this.decodeBufferPrefix(var1, var2);
  47.  
  48.       while(true) {
  49.          try {
  50.             int var5 = this.decodeLinePrefix(var1, var2);
  51.  
  52.             int var3;
  53.             for(var3 = 0; var3 + this.bytesPerAtom() < var5; var3 += this.bytesPerAtom()) {
  54.                this.decodeAtom(var1, var2, this.bytesPerAtom());
  55.                var4 += this.bytesPerAtom();
  56.             }
  57.  
  58.             if (var3 + this.bytesPerAtom() == var5) {
  59.                this.decodeAtom(var1, var2, this.bytesPerAtom());
  60.                var4 += this.bytesPerAtom();
  61.             } else {
  62.                this.decodeAtom(var1, var2, var5 - var3);
  63.                var4 += var5 - var3;
  64.             }
  65.  
  66.             this.decodeLineSuffix(var1, var2);
  67.          } catch (CEStreamExhausted var7) {
  68.             this.decodeBufferSuffix(var1, var2);
  69.             return;
  70.          }
  71.       }
  72.    }
  73.  
  74.    public byte[] decodeBuffer(String var1) throws IOException {
  75.       byte[] var2 = new byte[var1.length()];
  76.       var1.getBytes(0, var1.length(), var2, 0);
  77.       ByteArrayInputStream var3 = new ByteArrayInputStream(var2);
  78.       ByteArrayOutputStream var4 = new ByteArrayOutputStream();
  79.       this.decodeBuffer(var3, var4);
  80.       return var4.toByteArray();
  81.    }
  82.  
  83.    public byte[] decodeBuffer(InputStream var1) throws IOException {
  84.       ByteArrayOutputStream var2 = new ByteArrayOutputStream();
  85.       this.decodeBuffer(var1, var2);
  86.       return var2.toByteArray();
  87.    }
  88. }
  89.