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

  1. package sun.io;
  2.  
  3. import java.io.UnsupportedEncodingException;
  4.  
  5. public class ByteToCharJISAutoDetect extends ByteToCharConverter {
  6.    private String convName;
  7.    private ByteToCharConverter detectedConv;
  8.    private ByteToCharConverter defaultConv;
  9.  
  10.    public ByteToCharJISAutoDetect() {
  11.       try {
  12.          this.defaultConv = ByteToCharConverter.getConverter("8859_1");
  13.       } catch (UnsupportedEncodingException var1) {
  14.          this.defaultConv = new ByteToCharDefault();
  15.       }
  16.  
  17.       this.defaultConv.subChars = super.subChars;
  18.       this.defaultConv.subMode = super.subMode;
  19.    }
  20.  
  21.    public int flush(char[] var1, int var2, int var3) throws MalformedInputException, ConversionBufferFullException {
  22.       super.badInputLength = 0;
  23.       return this.detectedConv != null ? this.detectedConv.flush(var1, var2, var3) : this.defaultConv.flush(var1, var2, var3);
  24.    }
  25.  
  26.    public int convert(byte[] var1, int var2, int var3, char[] var4, int var5, int var6) throws UnknownCharacterException, MalformedInputException, ConversionBufferFullException {
  27.       int var7 = var2;
  28.       int var8 = var2 + var3;
  29.       String var10 = null;
  30.       ByteToCharConverter var11 = null;
  31.  
  32.       try {
  33.          if (this.detectedConv == null) {
  34.             for(int var12 = var7; var12 < var8; ++var12) {
  35.                int var13 = var1[var12] & 255;
  36.                if (var13 == 27) {
  37.                   this.convName = "ISO2022JP";
  38.                   break;
  39.                }
  40.  
  41.                if (var13 >= 129 && var13 <= 159) {
  42.                   this.convName = "SJIS";
  43.                   break;
  44.                }
  45.  
  46.                if (var13 >= 161 && var13 <= 223 || var13 >= 253 && var13 <= 254) {
  47.                   this.convName = "EUC_JP";
  48.                   break;
  49.                }
  50.  
  51.                if (var13 >= 224 && var13 <= 234) {
  52.                   if (var12 + 1 >= var8) {
  53.                      throw new MalformedInputException();
  54.                   }
  55.  
  56.                   ++var12;
  57.                   var13 = var1[var12] & 255;
  58.                   if (var13 >= 64 && var13 <= 126) {
  59.                      this.convName = "SJIS";
  60.                      break;
  61.                   }
  62.  
  63.                   if (var10 == null) {
  64.                      var10 = "SJIS";
  65.                   }
  66.                   break;
  67.                }
  68.  
  69.                if (var13 >= 235 && var13 <= 252) {
  70.                   if (var12 + 1 >= var8) {
  71.                      throw new MalformedInputException();
  72.                   }
  73.  
  74.                   ++var12;
  75.                   var13 = var1[var12] & 255;
  76.                   if (var13 >= 64 && var13 <= 126) {
  77.                      this.convName = "SJIS";
  78.                      break;
  79.                   }
  80.  
  81.                   if (var10 == null) {
  82.                      var10 = "EUC_JP";
  83.                   }
  84.                   break;
  85.                }
  86.             }
  87.  
  88.             if (this.convName != null) {
  89.                try {
  90.                   this.detectedConv = ByteToCharConverter.getConverter(this.convName);
  91.                   this.detectedConv.subChars = super.subChars;
  92.                   this.detectedConv.subMode = super.subMode;
  93.                } catch (UnsupportedEncodingException var24) {
  94.                   this.detectedConv = null;
  95.                   this.convName = null;
  96.                }
  97.             } else if (var10 != null) {
  98.                try {
  99.                   var11 = ByteToCharConverter.getConverter(var10);
  100.                   var11.subChars = super.subChars;
  101.                   var11.subMode = super.subMode;
  102.                } catch (UnsupportedEncodingException var23) {
  103.                   var11 = null;
  104.                   Object var26 = null;
  105.                }
  106.             }
  107.          }
  108.       } catch (Exception var25) {
  109.          this.detectedConv = this.defaultConv;
  110.       }
  111.  
  112.       int var9;
  113.       if (this.detectedConv != null) {
  114.          try {
  115.             var9 = this.detectedConv.convert(var1, var2, var3, var4, var5, var6);
  116.             super.charOff = this.detectedConv.nextCharIndex();
  117.             super.byteOff = this.detectedConv.nextByteIndex();
  118.             super.badInputLength = this.detectedConv.badInputLength;
  119.          } catch (UnknownCharacterException var20) {
  120.             super.charOff = this.detectedConv.nextCharIndex();
  121.             super.byteOff = this.detectedConv.nextByteIndex();
  122.             super.badInputLength = this.detectedConv.badInputLength;
  123.             throw var20;
  124.          } catch (MalformedInputException var21) {
  125.             super.charOff = this.detectedConv.nextCharIndex();
  126.             super.byteOff = this.detectedConv.nextByteIndex();
  127.             super.badInputLength = this.detectedConv.badInputLength;
  128.             throw var21;
  129.          } catch (ConversionBufferFullException var22) {
  130.             super.charOff = this.detectedConv.nextCharIndex();
  131.             super.byteOff = this.detectedConv.nextByteIndex();
  132.             super.badInputLength = this.detectedConv.badInputLength;
  133.             throw var22;
  134.          }
  135.       } else if (var11 != null) {
  136.          try {
  137.             var9 = var11.convert(var1, var2, var3, var4, var5, var6);
  138.             super.charOff = var11.nextCharIndex();
  139.             super.byteOff = var11.nextByteIndex();
  140.             super.badInputLength = var11.badInputLength;
  141.          } catch (UnknownCharacterException var17) {
  142.             super.charOff = var11.nextCharIndex();
  143.             super.byteOff = var11.nextByteIndex();
  144.             super.badInputLength = var11.badInputLength;
  145.             throw var17;
  146.          } catch (MalformedInputException var18) {
  147.             super.charOff = var11.nextCharIndex();
  148.             super.byteOff = var11.nextByteIndex();
  149.             super.badInputLength = var11.badInputLength;
  150.             throw var18;
  151.          } catch (ConversionBufferFullException var19) {
  152.             super.charOff = var11.nextCharIndex();
  153.             super.byteOff = var11.nextByteIndex();
  154.             super.badInputLength = var11.badInputLength;
  155.             throw var19;
  156.          }
  157.       } else {
  158.          try {
  159.             var9 = this.defaultConv.convert(var1, var2, var3, var4, var5, var6);
  160.             super.charOff = this.defaultConv.nextCharIndex();
  161.             super.byteOff = this.defaultConv.nextByteIndex();
  162.             super.badInputLength = this.defaultConv.badInputLength;
  163.          } catch (UnknownCharacterException var14) {
  164.             super.charOff = this.defaultConv.nextCharIndex();
  165.             super.byteOff = this.defaultConv.nextByteIndex();
  166.             super.badInputLength = this.defaultConv.badInputLength;
  167.             throw var14;
  168.          } catch (MalformedInputException var15) {
  169.             super.charOff = this.defaultConv.nextCharIndex();
  170.             super.byteOff = this.defaultConv.nextByteIndex();
  171.             super.badInputLength = this.defaultConv.badInputLength;
  172.             throw var15;
  173.          } catch (ConversionBufferFullException var16) {
  174.             super.charOff = this.defaultConv.nextCharIndex();
  175.             super.byteOff = this.defaultConv.nextByteIndex();
  176.             super.badInputLength = this.defaultConv.badInputLength;
  177.             throw var16;
  178.          }
  179.       }
  180.  
  181.       return var9;
  182.    }
  183.  
  184.    public void reset() {
  185.       if (this.detectedConv != null) {
  186.          this.detectedConv.reset();
  187.          this.detectedConv = null;
  188.          this.convName = null;
  189.       } else {
  190.          this.defaultConv.reset();
  191.       }
  192.    }
  193.  
  194.    public String getCharacterEncoding() {
  195.       return "JISAutoDetect";
  196.    }
  197. }
  198.