src/share/jaxws_classes/com/sun/xml/internal/dtdparser/XmlReader.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  69     private String assignedEncoding;
  70     private boolean closed;
  71 
  72     //
  73     // This class always delegates I/O to a reader, which gets
  74     // its data from the very beginning of the XML text.  It needs
  75     // to use a pushback stream since (a) autodetection can read
  76     // partial UTF-8 characters which need to be fully processed,
  77     // (b) the "Unicode" readers swallow characters that they think
  78     // are byte order marks, so tests fail if they don't see the
  79     // real byte order mark.
  80     //
  81     // It's got do this efficiently:  character I/O is solidly on the
  82     // critical path.  (So keep buffer length over 2 Kbytes to avoid
  83     // excess buffering. Many URL handlers stuff a BufferedInputStream
  84     // between here and the real data source, and larger buffers keep
  85     // that from slowing you down.)
  86     //
  87 
  88     /**
  89      * Constructs the reader from an input stream, auto-detecting
  90      * the encoding to use according to the heuristic specified
  91      * in the XML 1.0 recommendation.
  92      *
  93      * @param in the input stream from which the reader is constructed
  94      * @throws IOException on error, such as unrecognized encoding
  95      */
  96     public static Reader createReader(InputStream in) throws IOException {
  97         return new XmlReader(in);
  98     }
  99 
 100     /**
 101      * Creates a reader supporting the given encoding, mapping
 102      * from standard encoding names to ones that understood by
 103      * Java where necessary.
 104      *
 105      * @param in       the input stream from which the reader is constructed
 106      * @param encoding the IETF standard name of the encoding to use;
 107      *                 if null, auto-detection is used.
 108      * @throws IOException on error, including unrecognized encoding
 109      */
 110     public static Reader createReader(InputStream in, String encoding)
 111             throws IOException {
 112         if (encoding == null)
 113             return new XmlReader(in);
 114         if ("UTF-8".equalsIgnoreCase(encoding)
 115                 || "UTF8".equalsIgnoreCase(encoding))
 116             return new Utf8Reader(in);
 117         if ("US-ASCII".equalsIgnoreCase(encoding)
 118                 || "ASCII".equalsIgnoreCase(encoding))
 119             return new AsciiReader(in);
 120         if ("ISO-8859-1".equalsIgnoreCase(encoding)
 121         // plus numerous aliases ...
 122         )
 123             return new Iso8859_1Reader(in);
 124 
 125         //
 126         // What we really want is an administerable resource mapping
 127         // encoding names/aliases to classnames.  For example a property


   1 /*
   2  * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  69     private String assignedEncoding;
  70     private boolean closed;
  71 
  72     //
  73     // This class always delegates I/O to a reader, which gets
  74     // its data from the very beginning of the XML text.  It needs
  75     // to use a pushback stream since (a) autodetection can read
  76     // partial UTF-8 characters which need to be fully processed,
  77     // (b) the "Unicode" readers swallow characters that they think
  78     // are byte order marks, so tests fail if they don't see the
  79     // real byte order mark.
  80     //
  81     // It's got do this efficiently:  character I/O is solidly on the
  82     // critical path.  (So keep buffer length over 2 Kbytes to avoid
  83     // excess buffering. Many URL handlers stuff a BufferedInputStream
  84     // between here and the real data source, and larger buffers keep
  85     // that from slowing you down.)
  86     //
  87 
  88     /**
  89      * Constructs the reader from an input stream, autodetecting
  90      * the encoding to use according to the heuristic specified
  91      * in the XML 1.0 recommendation.
  92      *
  93      * @param in the input stream from which the reader is constructed
  94      * @throws IOException on error, such as unrecognized encoding
  95      */
  96     public static Reader createReader(InputStream in) throws IOException {
  97         return new XmlReader(in);
  98     }
  99 
 100     /**
 101      * Creates a reader supporting the given encoding, mapping
 102      * from standard encoding names to ones that understood by
 103      * Java where necessary.
 104      *
 105      * @param in       the input stream from which the reader is constructed
 106      * @param encoding the IETF standard name of the encoding to use;
 107      *                 if null, autodetection is used.
 108      * @throws IOException on error, including unrecognized encoding
 109      */
 110     public static Reader createReader(InputStream in, String encoding)
 111             throws IOException {
 112         if (encoding == null)
 113             return new XmlReader(in);
 114         if ("UTF-8".equalsIgnoreCase(encoding)
 115                 || "UTF8".equalsIgnoreCase(encoding))
 116             return new Utf8Reader(in);
 117         if ("US-ASCII".equalsIgnoreCase(encoding)
 118                 || "ASCII".equalsIgnoreCase(encoding))
 119             return new AsciiReader(in);
 120         if ("ISO-8859-1".equalsIgnoreCase(encoding)
 121         // plus numerous aliases ...
 122         )
 123             return new Iso8859_1Reader(in);
 124 
 125         //
 126         // What we really want is an administerable resource mapping
 127         // encoding names/aliases to classnames.  For example a property