1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.utils.xml;
20
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.Reader;
26 import java.net.URL;
27 import java.net.URLConnection;
28 import java.util.regex.Pattern;
29
30
31
32
33 @Deprecated
34 public class XmlStreamReader extends Reader {
35 private final org.apache.commons.io.input.XmlStreamReader reader;
36
37 private static String staticDefaultEncoding = null;
38
39
40
41
42 public static void setDefaultEncoding(String encoding) {
43 staticDefaultEncoding = encoding;
44 }
45
46
47
48
49 public static String getDefaultEncoding() {
50 return staticDefaultEncoding;
51 }
52
53
54
55
56
57 public XmlStreamReader(File file) throws IOException {
58 this(new FileInputStream(file));
59 }
60
61
62
63
64
65 public XmlStreamReader(InputStream is) throws IOException {
66 this(is, true);
67 }
68
69
70
71
72
73
74 public XmlStreamReader(InputStream is, boolean lenient) throws IOException {
75 reader = new org.apache.commons.io.input.XmlStreamReader(is, lenient, staticDefaultEncoding);
76 }
77
78
79
80
81
82 public XmlStreamReader(URL url) throws IOException {
83 this(url.openConnection());
84 }
85
86
87
88
89
90 public XmlStreamReader(URLConnection conn) throws IOException {
91 reader = new org.apache.commons.io.input.XmlStreamReader(conn, staticDefaultEncoding);
92 }
93
94
95
96
97
98
99 public XmlStreamReader(InputStream is, String httpContentType) throws IOException {
100 this(is, httpContentType, true);
101 }
102
103
104
105
106
107
108
109
110 public XmlStreamReader(InputStream is, String httpContentType, boolean lenient, String defaultEncoding)
111 throws IOException {
112 reader = new org.apache.commons.io.input.XmlStreamReader(
113 is, httpContentType, lenient, (defaultEncoding == null) ? staticDefaultEncoding : defaultEncoding);
114 }
115
116
117
118
119
120
121
122 public XmlStreamReader(InputStream is, String httpContentType, boolean lenient) throws IOException {
123 this(is, httpContentType, lenient, null);
124 }
125
126
127
128
129 public String getEncoding() {
130 return reader.getEncoding();
131 }
132
133
134 public int read(char[] buf, int offset, int len) throws IOException {
135 return reader.read(buf, offset, len);
136 }
137
138
139 public void close() throws IOException {
140 reader.close();
141 }
142
143 static final Pattern ENCODING_PATTERN =
144 Pattern.compile("<\\?xml.*encoding[\\s]*=[\\s]*((?:\".[^\"]*\")|(?:'.[^']*'))", Pattern.MULTILINE);
145 }