use of org.apache.jena.riot.RiotParseException in project jena by apache.
the class TokenizerText method hasNext.
@Override
public final boolean hasNext() {
if (finished)
return false;
if (token != null)
return true;
try {
skip();
if (reader.eof()) {
// close();
finished = true;
return false;
}
token = parseToken();
if (token == null) {
// close();
finished = true;
return false;
}
return true;
} catch (AtlasException ex) {
if (ex.getCause() != null) {
if (ex.getCause().getClass() == java.nio.charset.MalformedInputException.class)
throw new RiotParseException("Bad character encoding", reader.getLineNum(), reader.getColNum());
throw new RiotParseException("Bad input stream [" + ex.getCause() + "]", reader.getLineNum(), reader.getColNum());
}
throw new RiotParseException("Bad input stream", reader.getLineNum(), reader.getColNum());
}
}
use of org.apache.jena.riot.RiotParseException in project jena by apache.
the class LangEngine method nextToken.
protected final Token nextToken() {
if (eof())
return tokenEOF;
// Tokenizer errors appear here!
try {
Token t = peekIter.next();
currLine = t.getLine();
currCol = t.getColumn();
return t;
} catch (RiotParseException ex) {
// Intercept to log it.
raiseException(ex);
throw ex;
} catch (AtlasException ex) {
// Bad I/O
RiotParseException ex2 = new RiotParseException(ex.getMessage(), -1, -1);
raiseException(ex2);
throw ex2;
}
}
use of org.apache.jena.riot.RiotParseException in project jena by apache.
the class Upload method incomingData.
public static UploadDetails incomingData(HttpAction action, StreamRDF dest) {
ContentType ct = FusekiLib.getContentType(action);
if (ct == null) {
ServletOps.errorBadRequest("No content type");
return null;
}
if (matchContentType(ctMultipartFormData, ct)) {
return fileUploadWorker(action, dest);
}
// Single graph (or quads) in body.
String base = ActionLib.wholeRequestURL(action.request);
Lang lang = RDFLanguages.contentTypeToLang(ct.getContentType());
if (lang == null) {
ServletOps.errorBadRequest("Unknown content type for triples: " + ct);
return null;
}
InputStream input = null;
try {
input = action.request.getInputStream();
} catch (IOException ex) {
IO.exception(ex);
}
int len = action.request.getContentLength();
StreamRDFCounting countingDest = StreamRDFLib.count(dest);
try {
ActionSPARQL.parse(action, countingDest, input, lang, base);
UploadDetails details = new UploadDetails(countingDest.count(), countingDest.countTriples(), countingDest.countQuads());
action.log.info(format("[%d] Body: Content-Length=%d, Content-Type=%s, Charset=%s => %s : %s", action.id, len, ct.getContentType(), ct.getCharset(), lang.getName(), details.detailsStr()));
return details;
} catch (RiotParseException ex) {
action.log.info(format("[%d] Body: Content-Length=%d, Content-Type=%s, Charset=%s => %s : %s", action.id, len, ct.getContentType(), ct.getCharset(), lang.getName(), ex.getMessage()));
throw ex;
}
}
use of org.apache.jena.riot.RiotParseException in project jena by apache.
the class Upload method fileUploadWorker.
/** Process an HTTP upload of RDF files (triples or quads)
* Stream straight into a graph or dataset -- unlike SPARQL_Upload the destination
* is known at the start of the multipart file body
*/
public static UploadDetails fileUploadWorker(HttpAction action, StreamRDF dest) {
String base = ActionLib.wholeRequestURL(action.request);
ServletFileUpload upload = new ServletFileUpload();
//log.info(format("[%d] Upload: Field=%s ignored", action.id, fieldName)) ;
// Overall counting.
StreamRDFCounting countingDest = StreamRDFLib.count(dest);
try {
FileItemIterator iter = upload.getItemIterator(action.request);
while (iter.hasNext()) {
FileItemStream fileStream = iter.next();
if (fileStream.isFormField()) {
// Ignore?
String fieldName = fileStream.getFieldName();
InputStream stream = fileStream.openStream();
String value = Streams.asString(stream, "UTF-8");
ServletOps.errorBadRequest(format("Only files accepted in multipart file upload (got %s=%s)", fieldName, value));
}
//Ignore the field name.
//String fieldName = fileStream.getFieldName();
InputStream stream = fileStream.openStream();
// Process the input stream
String contentTypeHeader = fileStream.getContentType();
ContentType ct = ContentType.create(contentTypeHeader);
Lang lang = null;
if (!matchContentType(ctTextPlain, ct))
lang = RDFLanguages.contentTypeToLang(ct.getContentType());
if (lang == null) {
String name = fileStream.getName();
if (name == null || name.equals(""))
ServletOps.errorBadRequest("No name for content - can't determine RDF syntax");
lang = RDFLanguages.filenameToLang(name);
if (name.endsWith(".gz"))
stream = new GZIPInputStream(stream);
}
if (lang == null)
// Desperate.
lang = RDFLanguages.RDFXML;
String printfilename = fileStream.getName();
if (printfilename == null || printfilename.equals(""))
printfilename = "<none>";
// Before
// action.log.info(format("[%d] Filename: %s, Content-Type=%s, Charset=%s => %s",
// action.id, printfilename, ct.getContentType(), ct.getCharset(), lang.getName())) ;
// count just this step
StreamRDFCounting countingDest2 = StreamRDFLib.count(countingDest);
try {
ActionSPARQL.parse(action, countingDest2, stream, lang, base);
UploadDetails details1 = new UploadDetails(countingDest2.count(), countingDest2.countTriples(), countingDest2.countQuads());
action.log.info(format("[%d] Filename: %s, Content-Type=%s, Charset=%s => %s : %s", action.id, printfilename, ct.getContentType(), ct.getCharset(), lang.getName(), details1.detailsStr()));
} catch (RiotParseException ex) {
action.log.info(format("[%d] Filename: %s, Content-Type=%s, Charset=%s => %s : %s", action.id, printfilename, ct.getContentType(), ct.getCharset(), lang.getName(), ex.getMessage()));
throw ex;
}
}
} catch (ActionErrorException ex) {
throw ex;
} catch (Exception ex) {
ServletOps.errorOccurred(ex.getMessage());
}
// Overall results.
UploadDetails details = new UploadDetails(countingDest.count(), countingDest.countTriples(), countingDest.countQuads());
return details;
}
use of org.apache.jena.riot.RiotParseException in project jena by apache.
the class JSONInputIterator method nextToken.
protected final Token nextToken() {
if (eof())
return tokenEOF;
// Tokenizer errors appear here!
try {
Token t = peekIter.next();
currLine = t.getLine();
currCol = t.getColumn();
return t;
} catch (RiotParseException ex) {
// Intercept to log it.
raiseException(ex);
throw ex;
} catch (AtlasException ex) {
// Bad I/O
RiotParseException ex2 = new RiotParseException(ex.getMessage(), -1, -1);
raiseException(ex2);
throw ex2;
}
}
Aggregations