/** * Checks if the stream contains <i>Turtle</i> triple patterns. * * @param is input stream to be verified. * @return <code>true</code> if <i>Turtle</i> patterns are detected, <code>false</code> otherwise. * @throws IOException if there is an error checking the {@link java.io.InputStream} */ public static boolean checkTurtleFormat(InputStream is) throws IOException { String sample = extractDataSample(is, '.'); RDFParser turtleParser = Rio.createParser(RDFFormat.TURTLE); turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.VERIFY); turtleParser.setStopAtFirstError(true); turtleParser.setVerifyData(true); ByteArrayInputStream bais = new ByteArrayInputStream( sample.getBytes() ); try { turtleParser.parse(bais, ""); return true; } catch (Exception e) { return false; } }
/** * Parses the content of <code>is</code> input stream with the * specified parser <code>p</code> using <code>baseIRI</code>. * * @param format input format type. * @param is input stream containing <code>RDF</code>. * @param baseIRI base uri. * @return list of statements detected within the input stream. * @throws IOException if there is an error reading the {@link java.io.InputStream} */ public static Statement[] parseRDF(RDFFormat format, InputStream is, String baseIRI) throws IOException { final StatementCollector handler = new StatementCollector(); final RDFParser parser = getParser(format); parser.getParserConfig().set(BasicParserSettings.VERIFY_DATATYPE_VALUES, true); parser.setStopAtFirstError(true); parser.setPreserveBNodeIDs(true); parser.setRDFHandler(handler); parser.parse(is, baseIRI); return handler.getStatements().toArray( new Statement[handler.getStatements().size()] ); }
parser.setRDFHandler(this); parser.setParseErrorListener(this); parser.setStopAtFirstError(!skipInvalid); if (skipInvalid) { parser.set(BasicParserSettings.VERIFY_URI_SYNTAX, false);
verifyDataType ? RDFParser.DatatypeHandling.VERIFY : RDFParser.DatatypeHandling.IGNORE ); parser.setStopAtFirstError(stopAtFirstError); parser.setParseErrorListener( new InternalParseErrorListener(extractionResult) ); parser.setValueFactory(
rdfParser.setStopAtFirstError(true); rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);