home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupportInternational / i18n.jar / sun / io / ByteToCharISO2022.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  3.6 KB  |  240 lines

  1. package sun.io;
  2.  
  3. public abstract class ByteToCharISO2022 extends ByteToCharConverter {
  4.    protected String[] SODesignator;
  5.    protected String[] SS2Designator;
  6.    protected String[] SS3Designator;
  7.    protected ByteToCharConverter[] SOConverter;
  8.    protected ByteToCharConverter[] SS2Converter;
  9.    protected ByteToCharConverter[] SS3Converter;
  10.    private static final byte ISO_ESC = 27;
  11.    private static final byte ISO_SI = 15;
  12.    private static final byte ISO_SO = 14;
  13.    private static final byte ISO_SS2_7 = 78;
  14.    private static final byte ISO_SS3_7 = 79;
  15.    private static final byte MSB = -128;
  16.    private static final char REPLACE_CHAR = '∩┐╜';
  17.    private static final byte maximumDesignatorLength = 3;
  18.    private static final byte SOFlag = 0;
  19.    private static final byte SS2Flag = 1;
  20.    private static final byte SS3Flag = 2;
  21.    // $FF: renamed from: G0 byte
  22.    private static final byte field_0 = 0;
  23.    // $FF: renamed from: G1 byte
  24.    private static final byte field_1 = 1;
  25.    private ByteToCharConverter[] tmpConverter;
  26.    private int curSODes;
  27.    private int curSS2Des;
  28.    private int curSS3Des;
  29.    private boolean shiftout;
  30.    private byte[] remainByte = new byte[10];
  31.    private int remainIndex = -1;
  32.    private byte state;
  33.    private byte firstByte;
  34.  
  35.    public void reset() {
  36.       boolean var1 = false;
  37.       this.shiftout = false;
  38.       this.state = 0;
  39.       this.firstByte = 0;
  40.       this.curSODes = 0;
  41.       this.curSS2Des = 0;
  42.       this.curSS3Des = 0;
  43.       super.charOff = super.byteOff = 0;
  44.       this.remainIndex = -1;
  45.  
  46.       for(int var2 = 0; var2 < this.remainByte.length; ++var2) {
  47.          this.remainByte[var2] = 0;
  48.       }
  49.  
  50.    }
  51.  
  52.    public int flush(char[] var1, int var2, int var3) throws MalformedInputException {
  53.       if (this.state != 0) {
  54.          super.badInputLength = 0;
  55.          throw new MalformedInputException();
  56.       } else {
  57.          this.reset();
  58.          return 0;
  59.       }
  60.    }
  61.  
  62.    private byte[] savetyGetSrc(byte[] var1, int var2, int var3, int var4) {
  63.       byte[] var6;
  64.       if (var2 <= var3 - var4 + 1) {
  65.          var6 = new byte[var4];
  66.       } else {
  67.          var6 = new byte[var3 - var2];
  68.       }
  69.  
  70.       for(int var5 = 0; var5 < var6.length; ++var5) {
  71.          var6[var5] = var1[var2 + var5];
  72.       }
  73.  
  74.       return var6;
  75.    }
  76.  
  77.    private char getUnicode(byte var1, byte var2, byte var3) {
  78.       var1 = (byte)(var1 | -128);
  79.       var2 = (byte)(var2 | -128);
  80.       byte[] var4 = new byte[]{var1, var2};
  81.       char[] var5 = new char[1];
  82.       boolean var6 = false;
  83.       int var7 = 0;
  84.       switch (var3) {
  85.          case 0:
  86.             var7 = this.curSODes;
  87.             this.tmpConverter = this.SOConverter;
  88.             break;
  89.          case 1:
  90.             var7 = this.curSS2Des;
  91.             this.tmpConverter = this.SS2Converter;
  92.             break;
  93.          case 2:
  94.             var7 = this.curSS3Des;
  95.             this.tmpConverter = this.SS3Converter;
  96.       }
  97.  
  98.       for(int var11 = 0; var11 < this.tmpConverter.length; ++var11) {
  99.          if (var7 == var11) {
  100.             try {
  101.                this.tmpConverter[var11].convert(var4, 0, 2, var5, 0, 1);
  102.             } catch (Exception var8) {
  103.             }
  104.  
  105.             return var5[0];
  106.          }
  107.       }
  108.  
  109.       return '∩┐╜';
  110.    }
  111.  
  112.    public final int convert(byte[] var1, int var2, int var3, char[] var4, int var5, int var6) throws ConversionBufferFullException {
  113.       int var8 = 0;
  114.       super.charOff = var5;
  115.       super.byteOff = var2;
  116.  
  117.       while(super.byteOff < var3) {
  118.          if (super.charOff >= var6) {
  119.             throw new ConversionBufferFullException();
  120.          }
  121.  
  122.          if (this.remainIndex < 0) {
  123.             this.remainByte[0] = var1[super.byteOff];
  124.             this.remainIndex = 0;
  125.             ++super.byteOff;
  126.          }
  127.  
  128.          switch (this.remainByte[0]) {
  129.             case 14:
  130.                this.shiftout = true;
  131.                if (this.remainIndex > 0) {
  132.                   System.arraycopy(this.remainByte, 1, this.remainByte, 0, this.remainIndex);
  133.                }
  134.  
  135.                --this.remainIndex;
  136.                break;
  137.             case 15:
  138.                this.shiftout = false;
  139.                if (this.remainIndex > 0) {
  140.                   System.arraycopy(this.remainByte, 1, this.remainByte, 0, this.remainIndex);
  141.                }
  142.  
  143.                --this.remainIndex;
  144.                break;
  145.             case 27:
  146.                byte[] var9 = this.savetyGetSrc(var1, super.byteOff, var3, 3 - this.remainIndex);
  147.                System.arraycopy(var9, 0, this.remainByte, this.remainIndex + 1, var9.length);
  148.                this.remainIndex += var9.length;
  149.                super.byteOff += var9.length;
  150.                if (var9.length < 3 - this.remainIndex) {
  151.                   break;
  152.                }
  153.  
  154.                String var10 = new String(this.remainByte, 1, this.remainIndex);
  155.  
  156.                int var7;
  157.                for(var7 = 0; var7 < this.SODesignator.length; ++var7) {
  158.                   if (var10.indexOf(this.SODesignator[var7]) == 0) {
  159.                      this.curSODes = var7;
  160.                      var8 = this.SODesignator[var7].length();
  161.                      break;
  162.                   }
  163.                }
  164.  
  165.                if (var7 == this.SODesignator.length) {
  166.                   for(var7 = 0; var7 < this.SS2Designator.length; ++var7) {
  167.                      if (var10.indexOf(this.SS2Designator[var7]) == 0) {
  168.                         this.curSS2Des = var7;
  169.                         var8 = this.SS2Designator[var7].length();
  170.                         break;
  171.                      }
  172.                   }
  173.  
  174.                   if (var7 == this.SS2Designator.length) {
  175.                      for(var7 = 0; var7 < this.SS3Designator.length; ++var7) {
  176.                         if (var10.indexOf(this.SS3Designator[var7]) == 0) {
  177.                            this.curSS3Des = var7;
  178.                            var8 = this.SS3Designator[var7].length();
  179.                            break;
  180.                         }
  181.                      }
  182.  
  183.                      if (var7 == this.SS3Designator.length) {
  184.                         switch (this.remainByte[1]) {
  185.                            case 78:
  186.                               var4[super.charOff] = this.getUnicode(this.remainByte[2], this.remainByte[3], (byte)1);
  187.                               ++super.charOff;
  188.                               var8 = 3;
  189.                               break;
  190.                            case 79:
  191.                               var4[super.charOff] = this.getUnicode(this.remainByte[2], this.remainByte[3], (byte)2);
  192.                               ++super.charOff;
  193.                               var8 = 3;
  194.                               break;
  195.                            default:
  196.                               var8 = 0;
  197.                         }
  198.                      }
  199.                   }
  200.                }
  201.  
  202.                if (this.remainIndex <= var8) {
  203.                   this.remainIndex = -1;
  204.                } else {
  205.                   for(var7 = 0; var7 < this.remainIndex - var8; ++var7) {
  206.                      this.remainByte[var7] = this.remainByte[var8 + 1 + var7];
  207.                   }
  208.  
  209.                   this.remainIndex = var7 - 1;
  210.                }
  211.                break;
  212.             default:
  213.                if (!this.shiftout) {
  214.                   var4[super.charOff] = (char)this.remainByte[0];
  215.                   ++super.charOff;
  216.                } else {
  217.                   switch (this.state) {
  218.                      case 0:
  219.                         this.firstByte = this.remainByte[0];
  220.                         this.state = 1;
  221.                         break;
  222.                      case 1:
  223.                         var4[super.charOff] = this.getUnicode(this.firstByte, this.remainByte[0], (byte)0);
  224.                         ++super.charOff;
  225.                         this.state = 0;
  226.                   }
  227.                }
  228.  
  229.                if (this.remainIndex > 0) {
  230.                   System.arraycopy(this.remainByte, 1, this.remainByte, 0, this.remainIndex);
  231.                }
  232.  
  233.                --this.remainIndex;
  234.          }
  235.       }
  236.  
  237.       return super.charOff - var5;
  238.    }
  239. }
  240.