home *** CD-ROM | disk | FTP | other *** search
/ Online Today 2000 January / Onto0100.iso / pc / JAVA / MSJAVX86.EXE / xmldso.cab / com / ms / xml / util / XMLInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  5.3 KB  |  387 lines

  1. package com.ms.xml.util;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.OutputStream;
  8. import java.net.URL;
  9.  
  10. public class XMLInputStream extends InputStream {
  11.    static final int INPUTSR = 1;
  12.    static final int UCS2 = 2;
  13.    static final int ASCII = 3;
  14.    static final int INPUTSR_POP = 4;
  15.    static final int UCS2_POP = 5;
  16.    static final int ASCII_POP = 6;
  17.    static final int SIZE = 1024;
  18.    static final int INTUTF8 = 0;
  19.    static final int INTASCII = 1;
  20.    static final int INTUCS2 = 2;
  21.    static final int INTUCS4 = 3;
  22.    static final int INTEBCDIC = 4;
  23.    static final int INT1252 = 5;
  24.    private int[] next = new int[4];
  25.    private int index = -1;
  26.    // $FF: renamed from: in java.io.InputStream
  27.    private InputStream field_0;
  28.    private InputStreamReader insr;
  29.    private int pos = 0;
  30.    private String encoding;
  31.    private boolean littleendian;
  32.    private boolean byteOrderMark;
  33.    private int readState;
  34.    private boolean jdk11;
  35.    private XMLStreamReader xmlis = null;
  36.    private int intEncoding = -1;
  37.    private int[] buffer = new int[1024];
  38.    private int size = -1;
  39.    private boolean eof = false;
  40.    private boolean onWindows = false;
  41.    public boolean caseInsensitive;
  42.  
  43.    public void close() throws IOException {
  44.       if (this.xmlis != null) {
  45.          this.xmlis.close();
  46.       } else if (this.insr != null) {
  47.          this.insr.close();
  48.       } else {
  49.          if (this.field_0 != null) {
  50.             this.field_0.close();
  51.          }
  52.  
  53.       }
  54.    }
  55.  
  56.    public void setEncoding(String var1) throws IOException {
  57.       this.insr = null;
  58.       byte var3 = 0;
  59.       if (!var1.equalsIgnoreCase("ISO-10646-UCS-2") && !var1.equalsIgnoreCase("UCS-2")) {
  60.          String var2;
  61.          if (var1.equalsIgnoreCase("Shift_JIS")) {
  62.             if (this.onWindows) {
  63.                throw new IOException("SJIS not yet supported");
  64.             }
  65.  
  66.             var2 = "SJIS";
  67.          } else if (var1.equalsIgnoreCase("ISO-8859-1")) {
  68.             if (this.onWindows) {
  69.                throw new IOException("8859_1 not yet supported");
  70.             }
  71.  
  72.             var2 = "8859_1";
  73.          } else {
  74.             if (var1.equalsIgnoreCase("ISO-10646-UCS-4")) {
  75.                throw new IOException("UCS-4 not yet supported");
  76.             }
  77.  
  78.             if (var1.equalsIgnoreCase("UTF-8")) {
  79.                var2 = "UTF8";
  80.                var3 = 0;
  81.             } else {
  82.                if (this.onWindows) {
  83.                   if (!var1.equals("windows-1252")) {
  84.                      throw new IOException(var1 + " not yet supported");
  85.                   }
  86.  
  87.                   var3 = 5;
  88.                }
  89.  
  90.                var2 = var1;
  91.             }
  92.          }
  93.  
  94.          if (!this.encoding.equalsIgnoreCase("ASCII") && !this.encoding.equalsIgnoreCase("UTF-8")) {
  95.             throw new IOException("Illegal Change of Encoding");
  96.          } else if (this.onWindows) {
  97.             if (this.intEncoding != var3) {
  98.                this.xmlis.setEncoding(var3, this.index);
  99.                this.index = this.size = 0;
  100.                this.eof = false;
  101.             }
  102.  
  103.          } else if (this.encoding.equalsIgnoreCase("ASCII")) {
  104.             this.insr = null;
  105.             this.readState = 6;
  106.          } else if (this.jdk11) {
  107.             if (this.pos != -1) {
  108.                this.field_0.reset();
  109.                this.field_0.skip((long)(this.pos + 1));
  110.             }
  111.  
  112.             this.insr = new InputStreamReader(this.field_0, var2);
  113.             this.readState = 1;
  114.             this.encoding = var1;
  115.          } else {
  116.             throw new IOException(var2 + " is not supported by your Java Virtual Machine." + "  Try installing the latest VM from http://www.microsoft.com/java/download.htm");
  117.          }
  118.       } else if (!this.encoding.equalsIgnoreCase("UCS-2")) {
  119.          throw new IOException("Illegal Change of Encoding");
  120.       } else {
  121.          this.readState = 2;
  122.          this.encoding = "UCS-2";
  123.       }
  124.    }
  125.  
  126.    public XMLInputStream(URL var1) throws IOException {
  127.       try {
  128.          Class var2 = Class.forName("com.ms.xml.xmlstream.XMLStream");
  129.          this.xmlis = (XMLStreamReader)var2.newInstance();
  130.          this.intEncoding = this.xmlis.open(var1.toString());
  131.       } catch (Throwable var3) {
  132.          throw new IOException("Error opening input stream for \"" + var1.toString() + "\": " + var3.toString());
  133.       }
  134.  
  135.       this.onWindows = true;
  136.       switch (this.intEncoding) {
  137.          case 0:
  138.             this.encoding = "UTF-8";
  139.             return;
  140.          case 1:
  141.             this.encoding = "ASCII";
  142.             return;
  143.          case 2:
  144.             this.encoding = "UCS-2";
  145.             return;
  146.          case 3:
  147.             this.encoding = "UCS-4";
  148.             return;
  149.          case 4:
  150.             this.encoding = "EBCDIC";
  151.             return;
  152.          case 5:
  153.             this.encoding = "windows-1252";
  154.             return;
  155.          default:
  156.             throw new IOException("Error opening input stream for \"" + var1.toString() + "\"");
  157.       }
  158.    }
  159.  
  160.    public XMLInputStream(InputStream var1) {
  161.       String var2 = System.getProperty("java.version");
  162.       this.jdk11 = var2.equals("1.1");
  163.       this.littleendian = false;
  164.       this.caseInsensitive = false;
  165.       this.byteOrderMark = false;
  166.       this.encoding = "UTF-8";
  167.       this.field_0 = (InputStream)var1;
  168.       this.insr = null;
  169.       this.readState = 3;
  170.       boolean var3 = false;
  171.  
  172.       try {
  173.          char var4 = (char)((InputStream)var1).read();
  174.          char var5 = (char)((InputStream)var1).read();
  175.          char var6 = (char)((InputStream)var1).read();
  176.          char var7 = (char)((InputStream)var1).read();
  177.          if (var4 == 254 && var5 == 255 && var6 == 0 && var7 == '<') {
  178.             this.littleendian = false;
  179.             this.byteOrderMark = true;
  180.             this.readState = 5;
  181.             this.encoding = "UCS-2";
  182.          } else if (var4 == 255 && var5 == 254 && var6 == '<' && var7 == 0) {
  183.             this.littleendian = true;
  184.             this.byteOrderMark = true;
  185.             this.readState = 5;
  186.             this.encoding = "UCS-2";
  187.             this.field_0 = new ByteSwapInputStream((InputStream)var1);
  188.          } else if (var4 == 0 && var5 == '<' && var6 == 0 && var7 == '?') {
  189.             this.littleendian = false;
  190.             this.readState = 5;
  191.             this.encoding = "UCS-2";
  192.          } else if (var4 == '<' && var5 == 0 && var6 == '?' && var7 == 0) {
  193.             this.littleendian = true;
  194.             this.readState = 5;
  195.             this.encoding = "UCS-2";
  196.             this.field_0 = new ByteSwapInputStream((InputStream)var1);
  197.          } else if (var4 == '<' && var5 == '?' && Character.toUpperCase(var6) == 'X' && Character.toUpperCase(var7) == 'M') {
  198.             this.readState = 6;
  199.             this.encoding = "ASCII";
  200.          } else if (var4 == 0 && var5 == 0 && var6 == 0 && var7 == '<') {
  201.             this.readState = 6;
  202.             this.encoding = "UCS-4";
  203.          } else if (var4 == '<' && var5 == 0 && var6 == 0 && var7 == 0) {
  204.             this.readState = 6;
  205.             this.encoding = "UCS-4";
  206.          } else if (var4 == 0 && var5 == 0 && var6 == '<' && var7 == 0) {
  207.             this.readState = 6;
  208.             this.encoding = "UCS-4";
  209.          } else if (var4 == 0 && var5 == '<' && var6 == 0 && var7 == 0) {
  210.             this.readState = 6;
  211.             this.encoding = "UCS-4";
  212.          } else if (var4 == 'L' && var5 == 'o' && var6 == 231 && var7 == 212) {
  213.             this.readState = 6;
  214.             this.encoding = "EBCDIC";
  215.          } else {
  216.             var3 = true;
  217.          }
  218.  
  219.          if (!this.encoding.equals("UCS-2")) {
  220.             this.push(var7);
  221.             this.push(var6);
  222.             this.push(var5);
  223.             this.push(var4);
  224.          } else if (this.littleendian) {
  225.             this.push(var6);
  226.             this.push(var7);
  227.             if (!this.byteOrderMark) {
  228.                this.push(var4);
  229.                this.push(var5);
  230.             }
  231.          } else {
  232.             this.push(var7);
  233.             this.push(var6);
  234.             if (!this.byteOrderMark) {
  235.                this.push(var5);
  236.                this.push(var4);
  237.             }
  238.          }
  239.       } catch (IOException var9) {
  240.          var3 = true;
  241.       }
  242.  
  243.       this.pos = -1;
  244.       if (var3) {
  245.          try {
  246.             if (!this.jdk11) {
  247.                throw new IOException("Readers not supported in JDK 1.0");
  248.             }
  249.  
  250.             if (!((InputStream)var1).markSupported()) {
  251.                var1 = new BufferedInputStream((InputStream)var1);
  252.             }
  253.  
  254.             ((InputStream)var1).mark(4096);
  255.             this.insr = new InputStreamReader((InputStream)var1, "UTF8");
  256.             this.readState = 4;
  257.             this.encoding = "UTF-8";
  258.             return;
  259.          } catch (IOException var8) {
  260.             this.readState = 6;
  261.             this.encoding = "ASCII";
  262.          }
  263.       }
  264.  
  265.    }
  266.  
  267.    public int read() throws IOException {
  268.       if (this.onWindows) {
  269.          int var6 = 0;
  270.          if (this.index >= this.size) {
  271.             if (this.eof) {
  272.                return -1;
  273.             }
  274.  
  275.             try {
  276.                var6 = this.xmlis.read(this.buffer, 1024);
  277.             } catch (Exception var4) {
  278.                return -1;
  279.             }
  280.  
  281.             if (var6 <= 0) {
  282.                return -1;
  283.             }
  284.  
  285.             if (var6 < 1024) {
  286.                this.eof = true;
  287.             }
  288.  
  289.             this.size = var6;
  290.             this.index = 0;
  291.          }
  292.  
  293.          int var9 = this.buffer[this.index++];
  294.          if (var9 == 0) {
  295.             String var3 = "Stream error: unexpected null";
  296.             throw new IOException(var3);
  297.          } else {
  298.             return var9;
  299.          }
  300.       } else {
  301.          switch (this.readState) {
  302.             case 1:
  303.                ++this.pos;
  304.                return this.insr.read();
  305.             case 2:
  306.                int var5 = this.field_0.read();
  307.                if (var5 == -1) {
  308.                   return -1;
  309.                }
  310.  
  311.                int var8 = this.field_0.read();
  312.                return var5 << 8 | var8;
  313.             case 3:
  314.                return this.field_0.read();
  315.             case 4:
  316.                if (this.index >= 0) {
  317.                   int[] var11 = this.next;
  318.                   int var14 = this.index;
  319.                   this.index = var14 + -1;
  320.                   return var11[var14];
  321.                }
  322.  
  323.                this.readState = 1;
  324.                return this.read();
  325.             case 5:
  326.                int var1;
  327.                if (this.index >= 0) {
  328.                   int[] var10000 = this.next;
  329.                   int var10003 = this.index;
  330.                   this.index = var10003 + -1;
  331.                   var1 = var10000[var10003];
  332.                } else {
  333.                   this.readState = 2;
  334.                   var1 = this.field_0.read();
  335.                }
  336.  
  337.                if (var1 == -1) {
  338.                   return -1;
  339.                }
  340.  
  341.                int var2;
  342.                if (this.index >= 0) {
  343.                   int[] var10 = this.next;
  344.                   int var13 = this.index;
  345.                   this.index = var13 + -1;
  346.                   var2 = var10[var13];
  347.                } else {
  348.                   this.readState = 2;
  349.                   var2 = this.field_0.read();
  350.                }
  351.  
  352.                return var1 << 8 | var2;
  353.             case 6:
  354.             default:
  355.                if (this.index >= 0) {
  356.                   int[] var12 = this.next;
  357.                   int var15 = this.index;
  358.                   this.index = var15 + -1;
  359.                   return var12[var15];
  360.                } else {
  361.                   this.readState = 3;
  362.                   return this.field_0.read();
  363.                }
  364.          }
  365.       }
  366.    }
  367.  
  368.    private void push(char var1) {
  369.       if (this.index == 3) {
  370.          System.exit(0);
  371.       }
  372.  
  373.       this.next[++this.index] = var1;
  374.    }
  375.  
  376.    public XMLOutputStream createOutputStream(OutputStream var1) {
  377.       XMLOutputStream var2 = new XMLOutputStream(var1);
  378.  
  379.       try {
  380.          var2.setEncoding(this.encoding, this.littleendian, this.byteOrderMark);
  381.       } catch (IOException var3) {
  382.       }
  383.  
  384.       return var2;
  385.    }
  386. }
  387.