Indeed, I am such a scatterbrain. Thanks a lot Andy!

On Thu, Sep 22, 2011 at 6:18 PM, Andy Seaborne <[email protected]> wrote:
> On 22/09/11 16:21, Laurent Pellegrino wrote:
>>
>> Hi all,
>>
>> I am trying to parse a N-Quads file by using the following code:
>>
>>     static int line = 0;
>>
>>     public static void main(String[] args) {
>>
>>         Sink<Quad>  sink = new Sink<Quad>() {
>>             @Override
>>             public void send(final Quad quad) {
>>                 log.info("line=" + line + ", quad=" + quad);
>>                 line++;
>>             }
>>
>>             @Override
>>             public void close() {
>>             }
>>
>>             @Override
>>             public void flush() {
>>             }
>>         };
>>
>>         FileInputStream fis = null;
>>
>>         LangRIOT parser = null;
>>         try {
>>             fis = new FileInputStream("/absolute/path/to/nquads-chunk");
>>             parser = RiotReader.createParserNQuads(fis, sink);
>>         } catch (FileNotFoundException e) {
>>             e.printStackTrace();
>>         } finally {
>>             try {
>>                 fis.close();
>>             } catch (IOException e) {
>>                 e.printStackTrace();
>>             }
>>         }
>>
>>         parser.parse();
>>     }
>>
>> the file nquads-chun is available from:
>>
>> http://commondatastorage.googleapis.com/nquads/nquads-chunk
>>
>> When I run the parser, I get:
>>
>> Exception in thread "main" org.openjena.riot.RiotException: [line:
>> 574, col: 62] Bad input stream
>>        at
>> org.openjena.riot.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:110)
>>        at
>> org.openjena.riot.lang.LangEngine.raiseException(LangEngine.java:157)
>>        at org.openjena.riot.lang.LangEngine.nextToken(LangEngine.java:104)
>>        at org.openjena.riot.lang.LangNQuads.parseOne(LangNQuads.java:62)
>>        at org.openjena.riot.lang.LangNQuads.parseOne(LangNQuads.java:22)
>>        at org.openjena.riot.lang.LangNTuple.runParser(LangNTuple.java:58)
>>        at org.openjena.riot.lang.LangBase.parse(LangBase.java:42)
>>
>> where line 574 seems to be:
>>
>> <http://my.opera.com/carlOS%20X/xml/foaf#me>
>> <http://xmlns.com/foaf/0.1/knows>
>> <http://my.opera.com/allegro_noise/xml/foaf#me>
>> <http://my.opera.com/carlOS%20X/xml/foaf>  .
>>
>> which seems to respect the NQuads syntax correctly? any idea?
>>
>> Kind Regards,
>>
>> Laurent
>
> Laurent,
>
> The work of the parser is done in parser.parse()
>
> You've closed the input stream before the parser is called in the
> try-finally block.
>
> Try moving parser.parse(); inside the try{}
>
>            parser = RiotReader.createParserNQuads(fis, sink);
>            parser.parse();
>
> It gets someway because of the heavy read-ahead when the tokenizer is
> started.
>
> (error could be improved - the underlying error I get is "bad file
> descriptor" but that's on Linux).
>
>        Andy
>
>

Reply via email to