author | rriggs |
Fri, 23 Feb 2018 16:00:44 -0500 | |
changeset 48944 | 25aa8b9f1dae |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
14908
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
1 |
/* |
48944
25aa8b9f1dae
8198645: Use System.lineSeparator() instead of getProperty("line.separator")
rriggs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
14908
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
4 |
* |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
10 |
* |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
15 |
* accompanied this code). |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
16 |
* |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
20 |
* |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
23 |
* questions. |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
24 |
*/ |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
25 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
26 |
package jdk.internal.util.xml.impl; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
27 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
28 |
import java.io.BufferedOutputStream; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
29 |
import java.io.IOException; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
30 |
import java.io.OutputStream; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
31 |
import java.io.OutputStreamWriter; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
32 |
import java.io.UnsupportedEncodingException; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
33 |
import java.io.Writer; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
34 |
import java.nio.charset.Charset; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
35 |
import java.nio.charset.CharsetEncoder; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
36 |
import jdk.internal.util.xml.XMLStreamException; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
37 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
38 |
/** |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
39 |
* |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
40 |
* @author huizwang |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
41 |
*/ |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
42 |
public class XMLWriter { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
43 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
44 |
private Writer _writer; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
45 |
/** |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
46 |
* In some cases, this charset encoder is used to determine if a char is |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
47 |
* encodable by underlying writer. For example, an 8-bit char from the |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
48 |
* extended ASCII set is not encodable by 7-bit ASCII encoder. Unencodable |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
49 |
* chars are escaped using XML numeric entities. |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
50 |
*/ |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
51 |
private CharsetEncoder _encoder = null; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
52 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
53 |
public XMLWriter(OutputStream os, String encoding, Charset cs) throws XMLStreamException { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
54 |
_encoder = cs.newEncoder(); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
55 |
try { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
56 |
_writer = getWriter(os, encoding, cs); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
57 |
} catch (UnsupportedEncodingException ex) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
58 |
throw new XMLStreamException(ex); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
59 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
60 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
61 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
62 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
63 |
public boolean canEncode(char ch) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
64 |
if (_encoder == null) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
65 |
return false; |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
66 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
67 |
return (_encoder.canEncode(ch)); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
68 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
69 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
70 |
public void write(String s) |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
71 |
throws XMLStreamException { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
72 |
try { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
73 |
_writer.write(s.toCharArray()); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
74 |
// _writer.write(s.getBytes(Charset.forName(_encoding))); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
75 |
} catch (IOException e) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
76 |
throw new XMLStreamException("I/O error", e); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
77 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
78 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
79 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
80 |
public void write(String str, int off, int len) |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
81 |
throws XMLStreamException { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
82 |
try { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
83 |
_writer.write(str, off, len); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
84 |
} catch (IOException e) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
85 |
throw new XMLStreamException("I/O error", e); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
86 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
87 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
88 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
89 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
90 |
public void write(char[] cbuf, int off, int len) |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
91 |
throws XMLStreamException { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
92 |
try { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
93 |
_writer.write(cbuf, off, len); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
94 |
} catch (IOException e) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
95 |
throw new XMLStreamException("I/O error", e); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
96 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
97 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
98 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
99 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
100 |
void write(int b) |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
101 |
throws XMLStreamException { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
102 |
try { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
103 |
_writer.write(b); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
104 |
} catch (IOException e) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
105 |
throw new XMLStreamException("I/O error", e); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
106 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
107 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
108 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
109 |
void flush() throws XMLStreamException { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
110 |
try { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
111 |
_writer.flush(); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
112 |
} catch (IOException ex) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
113 |
throw new XMLStreamException(ex); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
114 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
115 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
116 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
117 |
void close() throws XMLStreamException { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
118 |
try { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
119 |
_writer.close(); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
120 |
} catch (IOException ex) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
121 |
throw new XMLStreamException(ex); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
122 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
123 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
124 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
125 |
private void nl() throws XMLStreamException { |
48944
25aa8b9f1dae
8198645: Use System.lineSeparator() instead of getProperty("line.separator")
rriggs
parents:
47216
diff
changeset
|
126 |
String lineEnd = System.lineSeparator(); |
14908
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
127 |
try { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
128 |
_writer.write(lineEnd); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
129 |
} catch (IOException e) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
130 |
throw new XMLStreamException("I/O error", e); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
131 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
132 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
133 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
134 |
/** |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
135 |
* Returns a writer for the specified encoding based on an output stream. |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
136 |
* |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
137 |
* @param output The output stream |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
138 |
* @param encoding The encoding |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
139 |
* @return A suitable writer |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
140 |
* @throws UnsupportedEncodingException There is no convertor to support |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
141 |
* this encoding |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
142 |
*/ |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
143 |
private Writer getWriter(OutputStream output, String encoding, Charset cs) |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
144 |
throws XMLStreamException, UnsupportedEncodingException |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
145 |
{ |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
146 |
if (cs != null) { |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
147 |
return (new OutputStreamWriter(new BufferedOutputStream(output), cs)); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
148 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
149 |
|
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
150 |
return new OutputStreamWriter(new BufferedOutputStream(output), encoding); |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
151 |
} |
1d01112e9ce5
8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff
changeset
|
152 |
} |