You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by vs...@apache.org on 2008/09/10 05:51:01 UTC
svn commit: r693696 -
/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java
Author: vsiveton
Date: Tue Sep 9 20:51:01 2008
New Revision: 693696
URL: http://svn.apache.org/viewvc?rev=693696&view=rev
Log:
o minor improvement when creating reader
Modified:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java
Modified: maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java?rev=693696&r1=693695&r2=693696&view=diff
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java (original)
+++ maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java Tue Sep 9 20:51:01 2008
@@ -460,25 +460,45 @@
}
}
- String detectedInputEncoding;
Reader reader;
+ FileInputStream is = null;
try
{
- detectedInputEncoding = getEncoding( inputFile );
+ is = new FileInputStream( inputFile );
- if ( detectedInputEncoding != null )
+ StringWriter w = new StringWriter();
+ IOUtil.copy( is, w );
+ String content = w.toString();
+
+ if ( content.startsWith( "<?xml" ) )
{
- reader = ReaderFactory.newReader( inputFile, detectedInputEncoding );
+ reader = ReaderFactory.newXmlReader( inputFile );
}
else
{
- reader = ReaderFactory.newPlatformReader( inputFile );
+ CharsetDetector detector = new CharsetDetector();
+ detector.setText( content.getBytes() );
+ CharsetMatch match = detector.detect();
+
+ String detectedInputEncoding = match.getName().toUpperCase( Locale.ENGLISH );
+ if ( detectedInputEncoding != null )
+ {
+ reader = ReaderFactory.newReader( inputFile, detectedInputEncoding );
+ }
+ else
+ {
+ reader = ReaderFactory.newPlatformReader( inputFile );
+ }
}
}
catch ( IOException e )
{
throw new ConverterException( "IOException: " + e.getMessage(), e );
}
+ finally
+ {
+ IOUtil.close( is );
+ }
Writer writer;
try
@@ -547,33 +567,4 @@
{
plexus.dispose();
}
-
- /**
- * @param f not null and should exist
- * @return the detected encoding from f
- * @throws IOException if any
- */
- private String getEncoding( File f )
- throws IOException
- {
- FileInputStream is = null;
- try
- {
- is = new FileInputStream( f );
-
- StringWriter w = new StringWriter();
- IOUtil.copy( is, w );
- String content = w.toString();
-
- CharsetDetector detector = new CharsetDetector();
- detector.setText( content.getBytes() );
- CharsetMatch match = detector.detect();
-
- return match.getName().toUpperCase( Locale.ENGLISH );
- }
- finally
- {
- IOUtil.close( is );
- }
- }
}