home *** CD-ROM | disk | FTP | other *** search
Wrap
package com.ms.xml.util; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.URL; public class XMLInputStream extends InputStream { static final int INPUTSR = 1; static final int UCS2 = 2; static final int ASCII = 3; static final int INPUTSR_POP = 4; static final int UCS2_POP = 5; static final int ASCII_POP = 6; static final int SIZE = 1024; static final int INTUTF8 = 0; static final int INTASCII = 1; static final int INTUCS2 = 2; static final int INTUCS4 = 3; static final int INTEBCDIC = 4; static final int INT1252 = 5; private int[] next = new int[4]; private int index = -1; // $FF: renamed from: in java.io.InputStream private InputStream field_0; private InputStreamReader insr; private int pos = 0; private String encoding; private boolean littleendian; private boolean byteOrderMark; private int readState; private boolean jdk11; private XMLStreamReader xmlis = null; private int intEncoding = -1; private int[] buffer = new int[1024]; private int size = -1; private boolean eof = false; private boolean onWindows = false; public boolean caseInsensitive; public void close() throws IOException { if (this.xmlis != null) { this.xmlis.close(); } else if (this.insr != null) { this.insr.close(); } else { if (this.field_0 != null) { this.field_0.close(); } } } public void setEncoding(String var1) throws IOException { this.insr = null; byte var3 = 0; if (!var1.equalsIgnoreCase("ISO-10646-UCS-2") && !var1.equalsIgnoreCase("UCS-2")) { String var2; if (var1.equalsIgnoreCase("Shift_JIS")) { if (this.onWindows) { throw new IOException("SJIS not yet supported"); } var2 = "SJIS"; } else if (var1.equalsIgnoreCase("ISO-8859-1")) { if (this.onWindows) { throw new IOException("8859_1 not yet supported"); } var2 = "8859_1"; } else { if (var1.equalsIgnoreCase("ISO-10646-UCS-4")) { throw new IOException("UCS-4 not yet supported"); } if (var1.equalsIgnoreCase("UTF-8")) { var2 = "UTF8"; var3 = 0; } else { if (this.onWindows) { if (!var1.equals("windows-1252")) { throw new IOException(var1 + " not yet supported"); } var3 = 5; } var2 = var1; } } if (!this.encoding.equalsIgnoreCase("ASCII") && !this.encoding.equalsIgnoreCase("UTF-8")) { throw new IOException("Illegal Change of Encoding"); } else if (this.onWindows) { if (this.intEncoding != var3) { this.xmlis.setEncoding(var3, this.index); this.index = this.size = 0; this.eof = false; } } else if (this.encoding.equalsIgnoreCase("ASCII")) { this.insr = null; this.readState = 6; } else if (this.jdk11) { if (this.pos != -1) { this.field_0.reset(); this.field_0.skip((long)(this.pos + 1)); } this.insr = new InputStreamReader(this.field_0, var2); this.readState = 1; this.encoding = var1; } else { 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"); } } else if (!this.encoding.equalsIgnoreCase("UCS-2")) { throw new IOException("Illegal Change of Encoding"); } else { this.readState = 2; this.encoding = "UCS-2"; } } public XMLInputStream(URL var1) throws IOException { try { Class var2 = Class.forName("com.ms.xml.xmlstream.XMLStream"); this.xmlis = (XMLStreamReader)var2.newInstance(); this.intEncoding = this.xmlis.open(var1.toString()); } catch (Throwable var3) { throw new IOException("Error opening input stream for \"" + var1.toString() + "\": " + var3.toString()); } this.onWindows = true; switch (this.intEncoding) { case 0: this.encoding = "UTF-8"; return; case 1: this.encoding = "ASCII"; return; case 2: this.encoding = "UCS-2"; return; case 3: this.encoding = "UCS-4"; return; case 4: this.encoding = "EBCDIC"; return; case 5: this.encoding = "windows-1252"; return; default: throw new IOException("Error opening input stream for \"" + var1.toString() + "\""); } } public XMLInputStream(InputStream var1) { String var2 = System.getProperty("java.version"); this.jdk11 = var2.equals("1.1"); this.littleendian = false; this.caseInsensitive = false; this.byteOrderMark = false; this.encoding = "UTF-8"; this.field_0 = (InputStream)var1; this.insr = null; this.readState = 3; boolean var3 = false; try { char var4 = (char)((InputStream)var1).read(); char var5 = (char)((InputStream)var1).read(); char var6 = (char)((InputStream)var1).read(); char var7 = (char)((InputStream)var1).read(); if (var4 == 254 && var5 == 255 && var6 == 0 && var7 == '<') { this.littleendian = false; this.byteOrderMark = true; this.readState = 5; this.encoding = "UCS-2"; } else if (var4 == 255 && var5 == 254 && var6 == '<' && var7 == 0) { this.littleendian = true; this.byteOrderMark = true; this.readState = 5; this.encoding = "UCS-2"; this.field_0 = new ByteSwapInputStream((InputStream)var1); } else if (var4 == 0 && var5 == '<' && var6 == 0 && var7 == '?') { this.littleendian = false; this.readState = 5; this.encoding = "UCS-2"; } else if (var4 == '<' && var5 == 0 && var6 == '?' && var7 == 0) { this.littleendian = true; this.readState = 5; this.encoding = "UCS-2"; this.field_0 = new ByteSwapInputStream((InputStream)var1); } else if (var4 == '<' && var5 == '?' && Character.toUpperCase(var6) == 'X' && Character.toUpperCase(var7) == 'M') { this.readState = 6; this.encoding = "ASCII"; } else if (var4 == 0 && var5 == 0 && var6 == 0 && var7 == '<') { this.readState = 6; this.encoding = "UCS-4"; } else if (var4 == '<' && var5 == 0 && var6 == 0 && var7 == 0) { this.readState = 6; this.encoding = "UCS-4"; } else if (var4 == 0 && var5 == 0 && var6 == '<' && var7 == 0) { this.readState = 6; this.encoding = "UCS-4"; } else if (var4 == 0 && var5 == '<' && var6 == 0 && var7 == 0) { this.readState = 6; this.encoding = "UCS-4"; } else if (var4 == 'L' && var5 == 'o' && var6 == 231 && var7 == 212) { this.readState = 6; this.encoding = "EBCDIC"; } else { var3 = true; } if (!this.encoding.equals("UCS-2")) { this.push(var7); this.push(var6); this.push(var5); this.push(var4); } else if (this.littleendian) { this.push(var6); this.push(var7); if (!this.byteOrderMark) { this.push(var4); this.push(var5); } } else { this.push(var7); this.push(var6); if (!this.byteOrderMark) { this.push(var5); this.push(var4); } } } catch (IOException var9) { var3 = true; } this.pos = -1; if (var3) { try { if (!this.jdk11) { throw new IOException("Readers not supported in JDK 1.0"); } if (!((InputStream)var1).markSupported()) { var1 = new BufferedInputStream((InputStream)var1); } ((InputStream)var1).mark(4096); this.insr = new InputStreamReader((InputStream)var1, "UTF8"); this.readState = 4; this.encoding = "UTF-8"; return; } catch (IOException var8) { this.readState = 6; this.encoding = "ASCII"; } } } public int read() throws IOException { if (this.onWindows) { int var6 = 0; if (this.index >= this.size) { if (this.eof) { return -1; } try { var6 = this.xmlis.read(this.buffer, 1024); } catch (Exception var4) { return -1; } if (var6 <= 0) { return -1; } if (var6 < 1024) { this.eof = true; } this.size = var6; this.index = 0; } int var9 = this.buffer[this.index++]; if (var9 == 0) { String var3 = "Stream error: unexpected null"; throw new IOException(var3); } else { return var9; } } else { switch (this.readState) { case 1: ++this.pos; return this.insr.read(); case 2: int var5 = this.field_0.read(); if (var5 == -1) { return -1; } int var8 = this.field_0.read(); return var5 << 8 | var8; case 3: return this.field_0.read(); case 4: if (this.index >= 0) { int[] var11 = this.next; int var14 = this.index; this.index = var14 + -1; return var11[var14]; } this.readState = 1; return this.read(); case 5: int var1; if (this.index >= 0) { int[] var10000 = this.next; int var10003 = this.index; this.index = var10003 + -1; var1 = var10000[var10003]; } else { this.readState = 2; var1 = this.field_0.read(); } if (var1 == -1) { return -1; } int var2; if (this.index >= 0) { int[] var10 = this.next; int var13 = this.index; this.index = var13 + -1; var2 = var10[var13]; } else { this.readState = 2; var2 = this.field_0.read(); } return var1 << 8 | var2; case 6: default: if (this.index >= 0) { int[] var12 = this.next; int var15 = this.index; this.index = var15 + -1; return var12[var15]; } else { this.readState = 3; return this.field_0.read(); } } } } private void push(char var1) { if (this.index == 3) { System.exit(0); } this.next[++this.index] = var1; } public XMLOutputStream createOutputStream(OutputStream var1) { XMLOutputStream var2 = new XMLOutputStream(var1); try { var2.setEncoding(this.encoding, this.littleendian, this.byteOrderMark); } catch (IOException var3) { } return var2; } }