abdera-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James M Snell (JIRA)" <j...@apache.org>
Subject [jira] Commented: (ABDERA-170) FOMParser.parse( InputStream in, String base, ParserOptions options) throws exeception
Date Thu, 29 May 2008 03:04:45 GMT

    [ https://issues.apache.org/jira/browse/ABDERA-170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12600671#action_12600671
] 

James M Snell commented on ABDERA-170:
--------------------------------------

FOMSniffingInputStream and FOMParser are not really meant to be used directly like this. 
Use this pattern instead:

    //...
    Parser parser = abdera.getParser();
    ParserOptions options = parser.getDefaultParserOptions();
    options.setAutodetectCharset(true);
    
    Document<Element> doc = parser.parse(is, options);
    
    System.out.println(doc.getRoot().toString());    
    System.out.println(doc.getCharset());

FOMParser uses FOMSniffingInputStream internally to do the charset detection.

> FOMParser.parse(    InputStream in,     String base,     ParserOptions options) throws
exeception
> -------------------------------------------------------------------------------------------------
>
>                 Key: ABDERA-170
>                 URL: https://issues.apache.org/jira/browse/ABDERA-170
>             Project: Abdera
>          Issue Type: Bug
>         Environment: linux Ubuntu 7.10, jvm Sun 1.6.0._03, abdera built from trunk source
with maven
>            Reporter: Stefano Linguerri
>         Attachments: testentry.xml
>
>
> This is on Trunk.
> The method FOMParser.parse(InputStream in, String base, ParserOptions options) use FOMSniffingInputStream
this class is the problem.
> FOMSniffingInputStream left the mark of inputstrem moved
> So when the input stream is passed to the parser an exception occurs.
> Two stupid test methods for Junit to verify the bug:
> This WORK:
>  @Test
>   public void testXMLFromFileWithoutFOMSniffingInputStream() throws Exception {
>     File file = new File("testentry.xml");
>     Abdera abdera = new Abdera();
>     FileInputStream is = new FileInputStream(file);
>     FOMParser fomParser = new FOMParser(abdera);
>     Document<Element> doc = fomParser.parse(is);
>     doc.getRoot().toString();
>   }
> This THROWS EXECEPTION
>   @Test
>   public void testXMLFromFileWithFOMSniffingInputStream() throws Exception {
>     File file = new File("testentry.xml");
>     Abdera abdera = new Abdera();
>     FileInputStream is = new FileInputStream(file);
>     FOMSniffingInputStream fomSniffingInputStream = new FOMSniffingInputStream(is);
>     fomSniffingInputStream.getEncoding();
>     FOMParser fomParser = new FOMParser(abdera);
>     Document<Element> doc = fomParser.parse(is);
>     doc.getRoot().toString();
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message