Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 1e909a13 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

- fixed a reentrance bug of InputStream/Reader when using parseString

parent 4d43bd96
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ import java.io.StringReader; ...@@ -26,6 +26,7 @@ import java.io.StringReader;
import java.io.Reader; import java.io.Reader;
import java.io.InputStream; import java.io.InputStream;
import java.io.File; import java.io.File;
import java.io.ByteArrayInputStream;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.lang.Integer; import java.lang.Integer;
...@@ -155,14 +156,16 @@ public class AlignmentParser { ...@@ -155,14 +156,16 @@ public class AlignmentParser {
* This dispatch is ridiculous, but that's life * This dispatch is ridiculous, but that's life
*/ */
private Alignment callParser( XMLParser p, Object o ) throws AlignmentException { private Alignment callParser( XMLParser p, Object o ) throws AlignmentException {
if ( o instanceof String ) return p.parse((String)o); if ( o instanceof URI ) return p.parse( ((URI)o).toString() );
if ( o instanceof String ) return p.parse( new ByteArrayInputStream( ((String)o).getBytes() ) );
if ( o instanceof Reader ) return p.parse((Reader)o); if ( o instanceof Reader ) return p.parse((Reader)o);
if ( o instanceof InputStream ) return p.parse((InputStream)o); if ( o instanceof InputStream ) return p.parse((InputStream)o);
throw new AlignmentException( "AlignmentParser: cannot parse :"+o ); throw new AlignmentException( "AlignmentParser: cannot parse :"+o );
} }
private Alignment callParser( RDFParser p, Object o ) throws AlignmentException { private Alignment callParser( RDFParser p, Object o ) throws AlignmentException {
if ( o instanceof String ) return p.parse((String)o); if ( o instanceof URI ) return p.parse( ((URI)o).toString() );
if ( o instanceof String ) return p.parse( new ByteArrayInputStream( ((String)o).getBytes() ) );
if ( o instanceof Reader ) return p.parse((Reader)o); if ( o instanceof Reader ) return p.parse((Reader)o);
if ( o instanceof InputStream ) return p.parse((InputStream)o); if ( o instanceof InputStream ) return p.parse((InputStream)o);
throw new AlignmentException( "AlignmentParser: cannot parse :"+o ); throw new AlignmentException( "AlignmentParser: cannot parse :"+o );
...@@ -173,7 +176,9 @@ public class AlignmentParser { ...@@ -173,7 +176,9 @@ public class AlignmentParser {
* @param s String the string to parse * @param s String the string to parse
*/ */
public Alignment parseString( String s ) throws AlignmentException { public Alignment parseString( String s ) throws AlignmentException {
parse( new StringReader( s ) ); // JE: The problem here is that InputStream are consumed by parsers
// So they must be opened again! Like Readers...
callParser( s );
return alignment; return alignment;
} }
...@@ -192,7 +197,11 @@ public class AlignmentParser { ...@@ -192,7 +197,11 @@ public class AlignmentParser {
*/ */
public Alignment parse( String uri ) throws AlignmentException { public Alignment parse( String uri ) throws AlignmentException {
this.uri = uri; // should be obsoloted this.uri = uri; // should be obsoloted
callParser( uri ); try {
callParser( new URI( uri ) );
} catch (URISyntaxException urisex) {
throw new AlignmentException( "Invalid URI : "+uri, urisex );
}
return alignment; return alignment;
} }
......
...@@ -202,8 +202,6 @@ public class RDFParser { ...@@ -202,8 +202,6 @@ public class RDFParser {
if (is == null) throw new AlignmentException("The reader must not be null"); if (is == null) throw new AlignmentException("The reader must not be null");
Model align = ModelFactory.createDefaultModel(); Model align = ModelFactory.createDefaultModel();
align.read( is, null ); align.read( is, null );
// Apparently this does not really works
//align.write(System.out);
return parse( align ); return parse( align );
} }
...@@ -211,7 +209,6 @@ public class RDFParser { ...@@ -211,7 +209,6 @@ public class RDFParser {
if (is == null) throw new AlignmentException("The inputstream must not be null"); if (is == null) throw new AlignmentException("The inputstream must not be null");
Model align = ModelFactory.createDefaultModel(); Model align = ModelFactory.createDefaultModel();
align.read( is, null ); align.read( is, null );
//debug align.write(System.out);
return parse( align ); return parse( align );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment