You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-dev@maven.apache.org by Benjamin Bentmann <be...@udo.edu> on 2008/12/07 00:07:49 UTC
Re: svn commit: r723989 - /maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
Hi Vincent,
> Author: vsiveton
> Date: Sat Dec 6 06:41:44 2008
> New Revision: 723989
>
> URL: http://svn.apache.org/viewvc?rev=723989&view=rev
> Log:
> DOXIA-265: Add an EntityResolver in AbstractXmlParser#getXmlReader()
>
> o added a simple cached file mechanism
>
> Modified:
> maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
> [...]
> + byte[] res = (byte[]) cache.get( systemId );
> + // already cached?
> + if ( res == null )
> + {
> + File temp =
> + new File( System.getProperty( "java.io.tmpdir" ), FileUtils.getFile( systemId ).getName() );
> + // maybe already as a temp file?
> + if ( !temp.exists() )
> + {
> + res = IOUtil.toByteArray( new URL( systemId ).openStream() );
> + IOUtil.copy( res, WriterFactory.newPlatformWriter( temp ) );
> + }
> + else
> + {
> + res = IOUtil.toByteArray( ReaderFactory.newPlatformReader( temp ) );
> + }
> +
> + cache.put( systemId, res );
> + }
> +
> + InputSource is = new InputSource( new ByteArrayInputStream( res ) );
> + is.setPublicId( publicId );
> + is.setSystemId( systemId );
> +
Is it safe to use a reader here, especially a platform reader? Byte
streams that don't match the intended encoding get crippled but is the
encoding of the data known here? Should this maybe just use
IOUtil.copy( byte[], OutputStream )
and
IOUtil.toByteArray( InputStream )
i.e. simply move bytes around instead of thinking about characters?
Benjamin
Re: svn commit: r723989 - /maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
Posted by Vincent Siveton <vi...@gmail.com>.
Hi Benjamin,
Right and I fixed it in r724309.
Thanks!
Vincent
2008/12/6 Benjamin Bentmann <be...@udo.edu>:
> Hi Vincent,
>
>> Author: vsiveton
>> Date: Sat Dec 6 06:41:44 2008
>> New Revision: 723989
>>
>> URL: http://svn.apache.org/viewvc?rev=723989&view=rev
>> Log:
>> DOXIA-265: Add an EntityResolver in AbstractXmlParser#getXmlReader()
>>
>> o added a simple cached file mechanism
>>
>> Modified:
>>
>> maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
>> [...]
>> + byte[] res = (byte[]) cache.get( systemId );
>> + // already cached?
>> + if ( res == null )
>> + {
>> + File temp =
>> + new File( System.getProperty( "java.io.tmpdir" ),
>> FileUtils.getFile( systemId ).getName() );
>> + // maybe already as a temp file?
>> + if ( !temp.exists() )
>> + {
>> + res = IOUtil.toByteArray( new URL( systemId
>> ).openStream() );
>> + IOUtil.copy( res, WriterFactory.newPlatformWriter(
>> temp ) );
>> + }
>> + else
>> + {
>> + res = IOUtil.toByteArray(
>> ReaderFactory.newPlatformReader( temp ) );
>> + }
>> +
>> + cache.put( systemId, res );
>> + }
>> +
>> + InputSource is = new InputSource( new ByteArrayInputStream(
>> res ) );
>> + is.setPublicId( publicId );
>> + is.setSystemId( systemId );
>> +
>
> Is it safe to use a reader here, especially a platform reader? Byte streams
> that don't match the intended encoding get crippled but is the encoding of
> the data known here? Should this maybe just use
> IOUtil.copy( byte[], OutputStream )
> and
> IOUtil.toByteArray( InputStream )
> i.e. simply move bytes around instead of thinking about characters?
>
>
> Benjamin
>