jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [7/7] jena git commit: Updated RIOT example
Date Fri, 10 Mar 2017 15:57:23 GMT
Updated RIOT example


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/edf8317b
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/edf8317b
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/edf8317b

Branch: refs/heads/master
Commit: edf8317baf46842e0f6dd5530bdd1666cc07ad7f
Parents: 0335d66
Author: Andy Seaborne <andy@apache.org>
Authored: Fri Mar 10 15:57:03 2017 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri Mar 10 15:57:03 2017 +0000

----------------------------------------------------------------------
 .../arq/examples/riot/ExRIOT_2.java             | 47 ++++++++------------
 1 file changed, 18 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/edf8317b/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java
----------------------------------------------------------------------
diff --git a/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java b/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java
index bfe6186..d751edd 100644
--- a/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java
+++ b/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java
@@ -19,13 +19,15 @@
 package arq.examples.riot;
 
 import java.io.FileInputStream ;
-import java.io.FileNotFoundException ;
+import java.io.IOException ;
 import java.io.InputStream ;
 
 import org.apache.jena.riot.RDFDataMgr ;
 import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.riot.ReaderRIOT ;
-import org.apache.jena.riot.system.* ;
+import org.apache.jena.riot.RDFParser ;
+import org.apache.jena.riot.system.ErrorHandlerFactory ;
+import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.riot.system.StreamRDFLib ;
 
 /** Example of using RIOT directly.
  * 
@@ -36,40 +38,27 @@ import org.apache.jena.riot.system.* ;
  */
 public class ExRIOT_2
 {
-    public static void main(String...argv) throws FileNotFoundException
+    public static void main(String...argv) throws IOException
     {
         // ---- Parse to a Sink.
         StreamRDF noWhere = StreamRDFLib.sinkNull() ;
 
         // RIOT controls the conversion from bytes to java chars.
-        InputStream in = new FileInputStream("data.trig") ;
+        try (InputStream in = new FileInputStream("data.trig")) {
+            RDFDataMgr.parse(noWhere, in, "http://example/base", RDFLanguages.TRIG) ;
+        }
         
-        RDFDataMgr.parse(noWhere, in, "http://example/base", RDFLanguages.TRIG, null) ;
-        
-        // --- Or create a parser and do the parsing as separate steps.
+        // --- Or create a parser and do the parsing with detailed setup.
         String baseURI = "http://example/base" ;
-            
+        
         // It is always better to use an InputStream, rather than a Java Reader.
         // The parsers will do the necessary character set conversion.  
-        in = new FileInputStream("data.trig") ;
-        
-        ReaderRIOT parser = RDFDataMgr.createReader(RDFLanguages.TRIG) ;
-        
-        // Access the setup of the RIOT built-in parsers.
-        
-        // Parser to first error or warning.
-        ErrorHandler errHandler = ErrorHandlerFactory.errorHandlerStrict ;
-
-        // Now enable stricter checking, even N-TRIPLES must have absolute URIs. 
-        ParserProfile profile = RiotLib.profile(baseURI, true, true, errHandler) ;
-
-        // Just set the error handler.
-        parser.setErrorHandler(errHandler) ;
-        
-        // Or replace the whole parser profile.
-        parser.setParserProfile(profile) ;
-
-        // Do the work.
-        parser.read(in, "http://example/base", null, noWhere, null);
+        try (InputStream in = new FileInputStream("data.trig")) {
+            RDFParser.create()
+                .lang(RDFLanguages.TRIG)
+                .errorHandler(ErrorHandlerFactory.errorHandlerStrict)
+                .base("http://example/base")
+                .parse(noWhere);
+        }
     }
 }


Mime
View raw message