Skip to content

Commit ab39f29

Browse files
committed
Add dependency on plexus-xml to keep compatibility and deprecate the reader/writer factories with no direct replacement
1 parent 8bf874b commit ab39f29

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ limitations under the License.
5555
</properties>
5656

5757
<dependencies>
58+
<dependency>
59+
<groupId>org.codehaus.plexus</groupId>
60+
<artifactId>plexus-xml</artifactId>
61+
<version>4.0.0-SNAPSHOT</version>
62+
<optional>true</optional>
63+
</dependency>
5864
<dependency>
5965
<groupId>junit</groupId>
6066
<artifactId>junit</artifactId>

src/main/java/org/codehaus/plexus/util/ReaderFactory.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19+
import org.codehaus.plexus.util.xml.XmlStreamReader;
20+
1921
import java.io.File;
2022
import java.io.IOException;
2123
import java.io.InputStream;
@@ -29,13 +31,18 @@
2931
/**
3032
* Utility to create Readers from streams, with explicit encoding choice: platform default, XML, or specified.
3133
*
34+
* @deprecated This class has been deprecated. When reading XML, users are encouraged to pass the {@code InputStream}
35+
* directory to the {@link org.codehaus.plexus.util.xml.pull.MXParser#setInput(InputStream, String)},
36+
* giving a {@code null} encoding to let the parser figure it out. For non xml usages, use the JDK
37+
* {@link Files} utility methods.
38+
*
3239
* @author <a href="mailto:[email protected]">Herve Boutemy</a>
3340
* @see Charset
3441
* @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
3542
*
3643
* @since 1.4.3
37-
* @deprecated use org.codehaus.plexus.util.xml.ReaderFactory from plexus-xml 4
3844
*/
45+
@Deprecated
3946
public class ReaderFactory
4047
{
4148
/**
@@ -92,6 +99,48 @@ public class ReaderFactory
9299
*/
93100
public static final String FILE_ENCODING = System.getProperty( "file.encoding" );
94101

102+
/**
103+
* Create a new Reader with XML encoding detection rules.
104+
*
105+
* @param in not null input stream.
106+
* @return an XML reader instance for the input stream.
107+
* @throws IOException if any.
108+
* @see XmlStreamReader
109+
*/
110+
public static XmlStreamReader newXmlReader( InputStream in )
111+
throws IOException
112+
{
113+
return new XmlStreamReader( in );
114+
}
115+
116+
/**
117+
* Create a new Reader with XML encoding detection rules.
118+
*
119+
* @param file not null file.
120+
* @return an XML reader instance for the input file.
121+
* @throws IOException if any.
122+
* @see XmlStreamReader
123+
*/
124+
public static XmlStreamReader newXmlReader( File file )
125+
throws IOException
126+
{
127+
return new XmlStreamReader( file );
128+
}
129+
130+
/**
131+
* Create a new Reader with XML encoding detection rules.
132+
*
133+
* @param url not null url.
134+
* @return an XML reader instance for the input url.
135+
* @throws IOException if any.
136+
* @see XmlStreamReader
137+
*/
138+
public static XmlStreamReader newXmlReader( URL url )
139+
throws IOException
140+
{
141+
return new XmlStreamReader( url );
142+
}
143+
95144
/**
96145
* Create a new Reader with default platform encoding.
97146
*

src/main/java/org/codehaus/plexus/util/WriterFactory.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19+
import org.codehaus.plexus.util.xml.XmlStreamWriter;
20+
1921
import java.io.File;
2022
import java.io.IOException;
2123
import java.io.OutputStream;
@@ -28,13 +30,16 @@
2830
/**
2931
* Utility to create Writers, with explicit encoding choice: platform default, XML, or specified.
3032
*
33+
* @deprecated This class has been deprecated. When writing XML, users can create the {@link XmlStreamWriter} instance
34+
* directly. For other usages, using {@link Files} helper methods is recommended.
35+
*
3136
* @author <a href="mailto:[email protected]">Herve Boutemy</a>
3237
* @see Charset
3338
* @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
3439
*
3540
* @since 1.4.4
36-
* @deprecated use org.codehaus.plexus.util.xml.WriterFactory from plexus-xml 4
3741
*/
42+
@Deprecated
3843
public class WriterFactory
3944
{
4045
/**
@@ -91,6 +96,34 @@ public class WriterFactory
9196
*/
9297
public static final String FILE_ENCODING = System.getProperty( "file.encoding" );
9398

99+
/**
100+
* Create a new Writer with XML encoding detection rules.
101+
*
102+
* @param out not null output stream.
103+
* @return an XML writer instance for the output stream.
104+
* @throws IOException if any.
105+
* @see XmlStreamWriter
106+
*/
107+
public static XmlStreamWriter newXmlWriter( OutputStream out )
108+
throws IOException
109+
{
110+
return new XmlStreamWriter( out );
111+
}
112+
113+
/**
114+
* Create a new Writer with XML encoding detection rules.
115+
*
116+
* @param file not null file.
117+
* @return an XML writer instance for the output file.
118+
* @throws IOException if any.
119+
* @see XmlStreamWriter
120+
*/
121+
public static XmlStreamWriter newXmlWriter(File file )
122+
throws IOException
123+
{
124+
return new XmlStreamWriter( file );
125+
}
126+
94127
/**
95128
* Create a new Writer with default platform encoding.
96129
*

0 commit comments

Comments
 (0)