use of org.apache.jena.riot.system.StreamRDF in project jena by apache.
the class DataValidatorHTML method executeHTML.
//static final String paramSyntaxExtended = "extendedSyntax" ;
public static void executeHTML(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
try {
// if ( log.isInfoEnabled() )
// log.info("data validation request") ;
String syntax = FusekiLib.safeParameter(httpRequest, paramSyntax);
if (syntax == null || syntax.equals(""))
syntax = RDFLanguages.NQUADS.getName();
Lang language = RDFLanguages.shortnameToLang(syntax);
if (language == null) {
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown syntax: " + syntax);
return;
}
Reader input = createInput(httpRequest, httpResponse);
ServletOutputStream outStream = httpResponse.getOutputStream();
ErrorHandlerMsg errorHandler = new ErrorHandlerMsg(outStream);
// Capture logging errors.
PrintStream stderr = System.err;
System.setErr(new PrintStream(outStream));
// Headers
setHeaders(httpResponse);
outStream.println("<html>");
printHead(outStream, "Jena Data Validator Report");
outStream.println("<body>");
outStream.println("<h1>RIOT Parser Report</h1>");
outStream.println("<p>Line and column numbers refer to original input</p>");
outStream.println("<p> </p>");
// Need to escape HTML.
OutputStream output1 = new OutputStreamNoHTML(new BufferedOutputStream(outStream));
StreamRDF output = StreamRDFWriter.getWriterStream(output1, Lang.NQUADS);
try {
startFixed(outStream);
RDFParser parser = RDFParser.create().lang(language).errorHandler(errorHandler).resolveURIs(false).build();
RiotException exception = null;
startFixed(outStream);
try {
output.start();
parser.parse(output);
output.finish();
output1.flush();
outStream.flush();
System.err.flush();
} catch (RiotException ex) {
ex.printStackTrace(stderr);
exception = ex;
}
} finally {
finishFixed(outStream);
System.err.flush();
System.setErr(stderr);
}
outStream.println("</body>");
outStream.println("</html>");
} catch (Exception ex) {
serviceLog.warn("Exception in validationRequest", ex);
}
}
use of org.apache.jena.riot.system.StreamRDF in project jena by apache.
the class SPARQL_REST_RW method addDataIntoNonTxn.
/** Add data where the destination does not support full transactions.
* In particular, with no abort, and actions probably going to the real storage
* parse errors can lead to partial updates. Instead, parse to a temporary
* graph, then insert that data.
* @param action
* @param cleanDest Whether to remove data first (true = PUT, false = POST)
* @return whether the target existed beforehand.
*/
protected static boolean addDataIntoNonTxn(HttpAction action, boolean overwrite) {
Graph graphTmp = GraphFactory.createGraphMem();
StreamRDF dest = StreamRDFLib.graph(graphTmp);
try {
incomingData(action, dest);
} catch (RiotException ex) {
errorBadRequest(ex.getMessage());
return false;
}
// Now insert into dataset
action.beginWrite();
Target target = determineTarget(action);
boolean existedBefore = false;
try {
if (log.isDebugEnabled())
log.debug(" ->" + target);
existedBefore = target.exists();
if (overwrite && existedBefore)
clearGraph(target);
FusekiLib.addDataInto(graphTmp, target.dsg, target.graphName);
action.commit();
return existedBefore;
} catch (Exception ex) {
// but it might and there is no harm safely trying.
try {
action.abort();
} catch (Exception ex2) {
}
errorOccurred(ex.getMessage());
return existedBefore;
} finally {
action.endWrite();
}
}
use of org.apache.jena.riot.system.StreamRDF in project jena by apache.
the class TestStreamRDFThrift method graph_01.
// graph_01 and graph_02 are the same test but use different ways to read/write the graph.
// Ditto dataset_01 and dataset_02
@Test
public void graph_01() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
// With values.
StreamRDF stream = BinRDF.streamToOutputStream(out, true);
StreamOps.graphToStream(graph, stream);
byte[] bytes = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Graph g2 = GraphFactory.createGraphMem();
StreamRDF stream2 = StreamRDFLib.graph(g2);
BinRDF.inputStreamToStream(in, stream2);
//assertTrue(graph.isIsomorphicWith(g2)) ;
//****
boolean b = IsoMatcher.isomorphic(graph, g2);
assertTrue(b);
// Stronger - same bNodes.
sameTerms(graph, g2);
}
use of org.apache.jena.riot.system.StreamRDF in project jena by apache.
the class TestStreamRDFThrift method dataset_01.
@Test
public void dataset_01() {
DatasetGraph dsg1 = datasetGraph;
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamRDF stream = BinRDF.streamToOutputStream(out);
StreamOps.datasetToStream(dsg1, stream);
byte[] bytes = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
DatasetGraph dsg2 = DatasetGraphFactory.create();
StreamRDF stream2 = StreamRDFLib.dataset(dsg2);
BinRDF.inputStreamToStream(in, stream2);
boolean b = IsoMatcher.isomorphic(dsg1, dsg2);
assertTrue(b);
// Stronger - same bNode and same as in original data.
Node obj = Iter.first(dsg1.listGraphNodes(), Node::isBlank);
termAsObject(dsg1, obj);
}
Aggregations