use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class ArrangedWriter method nextStatement.
private synchronized Statement nextStatement() {
if (stmtBySubject.isEmpty() && blanks.isEmpty()) {
assert queueSize == 0;
return null;
}
Set<Statement> stmts = null;
while (stmts == null) {
SubjectInContext last = stack.peekLast();
stmts = stmtBySubject.get(last);
if (stmts == null && last != null && blanks.contains(last.getSubject(), null, null, last.getContext())) {
stmts = queueBlankStatements(last);
} else if (stmts == null) {
stack.pollLast();
}
if (stack.isEmpty() && stmtBySubject.isEmpty()) {
Statement st = blanks.iterator().next();
stmts = queueBlankStatements(new SubjectInContext(st));
} else if (stack.isEmpty()) {
stmts = stmtBySubject.values().iterator().next();
}
}
Iterator<Statement> iter = stmts.iterator();
Statement next = iter.next();
queueSize--;
iter.remove();
SubjectInContext key = new SubjectInContext(next);
if (!key.equals(stack.peekLast())) {
stack.addLast(key);
}
if (!iter.hasNext()) {
stmtBySubject.remove(key);
}
Value obj = next.getObject();
if (obj instanceof BNode) {
// follow blank nodes before continuing with this subject
SubjectInContext bkey = new SubjectInContext((BNode) obj, next.getContext());
if (stack.contains(bkey)) {
// cycle detected
if (repeatBlankNodes) {
throw new RDFHandlerException("Blank node cycle detected. Try disabling " + BasicWriterSettings.INLINE_BLANK_NODES.getKey());
}
} else {
stack.addLast(bkey);
}
}
return next;
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class TriXParser method parse.
private void parse(InputSource inputStreamOrReader) throws IOException, RDFParseException, RDFHandlerException {
clear();
try {
if (rdfHandler != null) {
rdfHandler.startRDF();
}
XMLReader xmlReader;
if (getParserConfig().isSet(XMLParserSettings.CUSTOM_XML_READER)) {
xmlReader = getParserConfig().get(XMLParserSettings.CUSTOM_XML_READER);
} else {
xmlReader = XMLReaderFactory.createXMLReader();
}
xmlReader.setErrorHandler(this);
saxParser = new SimpleSAXParser(xmlReader);
saxParser.setPreserveWhitespace(true);
saxParser.setListener(new TriXSAXHandler());
saxParser.parse(inputStreamOrReader);
} catch (SAXParseException e) {
Exception wrappedExc = e.getException();
if (wrappedExc == null) {
reportFatalError(e, e.getLineNumber(), e.getColumnNumber());
} else {
reportFatalError(wrappedExc, e.getLineNumber(), e.getColumnNumber());
}
} catch (SAXException e) {
Exception wrappedExc = e.getException();
if (wrappedExc == null) {
reportFatalError(e);
} else if (wrappedExc instanceof RDFParseException) {
throw (RDFParseException) wrappedExc;
} else if (wrappedExc instanceof RDFHandlerException) {
throw (RDFHandlerException) wrappedExc;
} else {
reportFatalError(wrappedExc);
}
} finally {
clear();
}
if (rdfHandler != null) {
rdfHandler.endRDF();
}
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class TriXWriter method startRDF.
public void startRDF() throws RDFHandlerException {
if (writingStarted) {
throw new RDFHandlerException("Document writing has already started");
}
try {
if (getWriterConfig().get(XMLWriterSettings.INCLUDE_XML_PI)) {
xmlWriter.startDocument();
}
xmlWriter.setAttribute("xmlns", NAMESPACE);
xmlWriter.startTag(ROOT_TAG);
} catch (IOException e) {
throw new RDFHandlerException(e);
} finally {
writingStarted = true;
}
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class BinaryRDFWriter method handleComment.
public void handleComment(String comment) throws RDFHandlerException {
startRDF();
try {
out.writeByte(COMMENT);
writeString(comment);
} catch (IOException e) {
throw new RDFHandlerException(e);
}
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class BinaryRDFWriter method startRDF.
public void startRDF() throws RDFHandlerException {
if (!writingStarted) {
writingStarted = true;
try {
out.write(MAGIC_NUMBER);
out.writeInt(FORMAT_VERSION);
} catch (IOException e) {
throw new RDFHandlerException(e);
}
}
}
Aggregations