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_ASCII.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  2.1 KB  |  146 lines

  1. package sun.io;
  2.  
  3. public abstract class CharToByteDBCS_ASCII extends CharToByteConverter {
  4.    private char highHalfZoneCode;
  5.    private byte[] outputByte = new byte[2];
  6.    protected short[] index1;
  7.    protected String index2;
  8.    protected String index2a;
  9.    protected int mask1;
  10.    protected int mask2;
  11.    protected int shift;
  12.  
  13.    public int flush(byte[] var1, int var2, int var3) throws MalformedInputException, ConversionBufferFullException {
  14.       if (this.highHalfZoneCode != 0) {
  15.          this.reset();
  16.          super.badInputLength = 0;
  17.          throw new MalformedInputException();
  18.       } else {
  19.          this.reset();
  20.          return 0;
  21.       }
  22.    }
  23.  
  24.    public int convert(char[] var1, int var2, int var3, byte[] var4, int var5, int var6) throws UnknownCharacterException, MalformedInputException, ConversionBufferFullException {
  25.       super.byteOff = var5;
  26.  
  27.       int var8;
  28.       for(super.charOff = var2; super.charOff < var3; super.charOff += var8) {
  29.          char var7;
  30.          if (this.highHalfZoneCode == 0) {
  31.             var7 = var1[super.charOff];
  32.             var8 = 1;
  33.          } else {
  34.             var7 = this.highHalfZoneCode;
  35.             var8 = 0;
  36.             this.highHalfZoneCode = 0;
  37.          }
  38.  
  39.          if (var7 >= '\ud800' && var7 <= '\udbff') {
  40.             if (super.charOff + var8 >= var3) {
  41.                this.highHalfZoneCode = var7;
  42.                super.charOff += var8;
  43.                break;
  44.             }
  45.  
  46.             var7 = var1[super.charOff + var8];
  47.             if (var7 < '\udc00' || var7 > '\udfff') {
  48.                super.badInputLength = 1;
  49.                throw new MalformedInputException();
  50.             }
  51.  
  52.             if (!super.subMode) {
  53.                super.badInputLength = 2;
  54.                throw new UnknownCharacterException();
  55.             }
  56.  
  57.             if (super.subBytes.length == 1) {
  58.                this.outputByte[0] = 0;
  59.                this.outputByte[1] = super.subBytes[0];
  60.             } else {
  61.                this.outputByte[0] = super.subBytes[0];
  62.                this.outputByte[1] = super.subBytes[1];
  63.             }
  64.  
  65.             ++var8;
  66.          } else {
  67.             if (var7 >= '\udc00' && var7 <= '\udfff') {
  68.                super.badInputLength = 1;
  69.                throw new MalformedInputException();
  70.             }
  71.  
  72.             int var9 = this.index1[(var7 & this.mask1) >> this.shift] + (var7 & this.mask2);
  73.             char var10;
  74.             if (var9 < 15000) {
  75.                var10 = this.index2.charAt(var9);
  76.             } else {
  77.                var10 = this.index2a.charAt(var9 - 15000);
  78.             }
  79.  
  80.             this.outputByte[0] = (byte)((var10 & '\uff00') >> 8);
  81.             this.outputByte[1] = (byte)(var10 & 255);
  82.          }
  83.  
  84.          if (this.outputByte[0] == 0 && this.outputByte[1] == 0 && var7 != 0) {
  85.             if (!super.subMode) {
  86.                super.badInputLength = 1;
  87.                throw new UnknownCharacterException();
  88.             }
  89.  
  90.             if (super.subBytes.length == 1) {
  91.                this.outputByte[0] = 0;
  92.                this.outputByte[1] = super.subBytes[0];
  93.             } else {
  94.                this.outputByte[0] = super.subBytes[0];
  95.                this.outputByte[1] = super.subBytes[1];
  96.             }
  97.          }
  98.  
  99.          byte var11;
  100.          if (this.outputByte[0] == 0) {
  101.             var11 = 1;
  102.          } else {
  103.             var11 = 2;
  104.          }
  105.  
  106.          if (super.byteOff + var11 > var6) {
  107.             throw new ConversionBufferFullException();
  108.          }
  109.  
  110.          if (var11 == 1) {
  111.             var4[super.byteOff++] = this.outputByte[1];
  112.          } else {
  113.             var4[super.byteOff++] = this.outputByte[0];
  114.             var4[super.byteOff++] = this.outputByte[1];
  115.          }
  116.       }
  117.  
  118.       return super.byteOff - var5;
  119.    }
  120.  
  121.    public void reset() {
  122.       super.charOff = super.byteOff = 0;
  123.       this.highHalfZoneCode = 0;
  124.    }
  125.  
  126.    public int getMaxBytesPerChar() {
  127.       return 2;
  128.    }
  129.  
  130.    public boolean canConvert(char var1) {
  131.       int var2 = this.index1[(var1 & this.mask1) >> this.shift] + (var1 & this.mask2);
  132.       char var3;
  133.       if (var2 < 15000) {
  134.          var3 = this.index2.charAt(var2);
  135.       } else {
  136.          var3 = this.index2a.charAt(var2 - 15000);
  137.       }
  138.  
  139.       if (var3 != 0) {
  140.          return true;
  141.       } else {
  142.          return var1 == 0;
  143.       }
  144.    }
  145. }
  146.