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

  1. package sun.io;
  2.  
  3. public abstract class CharToByteDBCS_EBCDIC extends CharToByteConverter {
  4.    private static final int SBCS = 0;
  5.    private static final int DBCS = 1;
  6.    // $FF: renamed from: SO byte
  7.    private static final byte field_0 = 14;
  8.    // $FF: renamed from: SI byte
  9.    private static final byte field_1 = 15;
  10.    private int currentState = 0;
  11.    private char highHalfZoneCode = 0;
  12.    private byte[] outputByte = new byte[2];
  13.    protected short[] index1;
  14.    protected String index2;
  15.    protected String index2a;
  16.    protected int mask1;
  17.    protected int mask2;
  18.    protected int shift;
  19.  
  20.    public int flush(byte[] var1, int var2, int var3) throws MalformedInputException, ConversionBufferFullException {
  21.       int var4 = 0;
  22.       if (this.highHalfZoneCode != 0) {
  23.          this.reset();
  24.          super.badInputLength = 0;
  25.          throw new MalformedInputException();
  26.       } else {
  27.          if (this.currentState == 1) {
  28.             if (var2 >= var3) {
  29.                throw new ConversionBufferFullException();
  30.             }
  31.  
  32.             var1[var2] = 15;
  33.             ++var4;
  34.          }
  35.  
  36.          this.reset();
  37.          return var4;
  38.       }
  39.    }
  40.  
  41.    public int convert(char[] var1, int var2, int var3, byte[] var4, int var5, int var6) throws UnknownCharacterException, MalformedInputException, ConversionBufferFullException {
  42.       super.byteOff = var5;
  43.  
  44.       int var8;
  45.       for(super.charOff = var2; super.charOff < var3; super.charOff += var8) {
  46.          char var7;
  47.          if (this.highHalfZoneCode == 0) {
  48.             var7 = var1[super.charOff];
  49.             var8 = 1;
  50.          } else {
  51.             var7 = this.highHalfZoneCode;
  52.             var8 = 0;
  53.             this.highHalfZoneCode = 0;
  54.          }
  55.  
  56.          if (var7 >= '\ud800' && var7 <= '\udbff') {
  57.             if (super.charOff + var8 >= var3) {
  58.                this.highHalfZoneCode = var7;
  59.                super.charOff += var8;
  60.                break;
  61.             }
  62.  
  63.             var7 = var1[super.charOff + var8];
  64.             if (var7 < '\udc00' || var7 > '\udfff') {
  65.                super.badInputLength = 1;
  66.                throw new MalformedInputException();
  67.             }
  68.  
  69.             if (!super.subMode) {
  70.                super.badInputLength = 2;
  71.                throw new UnknownCharacterException();
  72.             }
  73.  
  74.             if (super.subBytes.length == 1) {
  75.                this.outputByte[0] = 0;
  76.                this.outputByte[1] = super.subBytes[0];
  77.             } else {
  78.                this.outputByte[0] = super.subBytes[0];
  79.                this.outputByte[1] = super.subBytes[1];
  80.             }
  81.  
  82.             ++var8;
  83.          } else {
  84.             if (var7 >= '\udc00' && var7 <= '\udfff') {
  85.                super.badInputLength = 1;
  86.                throw new MalformedInputException();
  87.             }
  88.  
  89.             int var9 = this.index1[(var7 & this.mask1) >> this.shift] + (var7 & this.mask2);
  90.             char var10;
  91.             if (var9 < 15000) {
  92.                var10 = this.index2.charAt(var9);
  93.             } else {
  94.                var10 = this.index2a.charAt(var9 - 15000);
  95.             }
  96.  
  97.             this.outputByte[0] = (byte)((var10 & '\uff00') >> 8);
  98.             this.outputByte[1] = (byte)(var10 & 255);
  99.          }
  100.  
  101.          if (this.outputByte[0] == 0 && this.outputByte[1] == 0 && var7 != 0) {
  102.             if (!super.subMode) {
  103.                super.badInputLength = 1;
  104.                throw new UnknownCharacterException();
  105.             }
  106.  
  107.             if (super.subBytes.length == 1) {
  108.                this.outputByte[0] = 0;
  109.                this.outputByte[1] = super.subBytes[0];
  110.             } else {
  111.                this.outputByte[0] = super.subBytes[0];
  112.                this.outputByte[1] = super.subBytes[1];
  113.             }
  114.          }
  115.  
  116.          if (this.currentState == 1 && this.outputByte[0] == 0) {
  117.             if (super.byteOff >= var6) {
  118.                throw new ConversionBufferFullException();
  119.             }
  120.  
  121.             this.currentState = 0;
  122.             var4[super.byteOff++] = 15;
  123.          } else if (this.currentState == 0 && this.outputByte[0] != 0) {
  124.             if (super.byteOff >= var6) {
  125.                throw new ConversionBufferFullException();
  126.             }
  127.  
  128.             this.currentState = 1;
  129.             var4[super.byteOff++] = 14;
  130.          }
  131.  
  132.          byte var11;
  133.          if (this.currentState == 1) {
  134.             var11 = 2;
  135.          } else {
  136.             var11 = 1;
  137.          }
  138.  
  139.          if (super.byteOff + var11 > var6) {
  140.             throw new ConversionBufferFullException();
  141.          }
  142.  
  143.          if (this.currentState == 0) {
  144.             var4[super.byteOff++] = this.outputByte[1];
  145.          } else {
  146.             var4[super.byteOff++] = this.outputByte[0];
  147.             var4[super.byteOff++] = this.outputByte[1];
  148.          }
  149.       }
  150.  
  151.       return super.byteOff - var5;
  152.    }
  153.  
  154.    public void reset() {
  155.       super.charOff = super.byteOff = 0;
  156.       this.highHalfZoneCode = 0;
  157.       this.currentState = 0;
  158.    }
  159.  
  160.    public int getMaxBytesPerChar() {
  161.       return 3;
  162.    }
  163.  
  164.    public void setSubstitutionBytes(byte[] var1) throws IllegalArgumentException {
  165.       if (var1.length <= 2 && var1.length != 0) {
  166.          super.subBytes = new byte[var1.length];
  167.          System.arraycopy(var1, 0, super.subBytes, 0, var1.length);
  168.       } else {
  169.          throw new IllegalArgumentException();
  170.       }
  171.    }
  172.  
  173.    public boolean canConvert(char var1) {
  174.       int var2 = this.index1[(var1 & this.mask1) >> this.shift] + (var1 & this.mask2);
  175.       char var3;
  176.       if (var2 < 15000) {
  177.          var3 = this.index2.charAt(var2);
  178.       } else {
  179.          var3 = this.index2a.charAt(var2 - 15000);
  180.       }
  181.  
  182.       if (var3 != 0) {
  183.          return true;
  184.       } else {
  185.          return var1 == 0;
  186.       }
  187.    }
  188. }
  189.