use of org.apache.jena.sparql.ARQException in project jena by apache.
the class TSVInput method booleanFromTSV.
/**
* Reads SPARQL Boolean result from TSV
* @param in Input Stream
* @return boolean
*/
public static boolean booleanFromTSV(InputStream in) {
BufferedReader reader = IO.asBufferedUTF8(in);
String str = null;
try {
// First try to parse the header
str = reader.readLine();
if (str == null)
throw new ARQException("TSV Boolean Results malformed, input is empty");
// Remove extraneous white space
str = str.trim();
// Expect a header row with single ?_askResult variable
if (!str.equals("?_askResult"))
throw new ARQException("TSV Boolean Results malformed, did not get expected ?_askResult header row");
// Then try to parse the boolean result
str = reader.readLine();
if (str == null)
throw new ARQException("TSV Boolean Results malformed, unexpected end of input after header row");
str = str.trim();
if (str.equalsIgnoreCase("true") || str.equalsIgnoreCase("yes")) {
return true;
} else if (str.equalsIgnoreCase("false") || str.equalsIgnoreCase("no")) {
return false;
} else {
throw new ARQException("TSV Boolean Results malformed, expected one of - true yes false no - but got " + str);
}
} catch (IOException ex) {
throw new ARQException(ex);
}
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class CSVInput method booleanFromCSV.
public static boolean booleanFromCSV(InputStream in) {
CSVParser parser = CSVParser.create(in);
final List<Var> vars = vars(parser);
if (vars.size() != 1) {
throw new ARQException("CSV Boolean Results malformed: variables line='" + vars + "'");
}
if (!vars.get(0).getName().equals("_askResult")) {
FmtLog.warn(log, "Boolean result variable is '%s', not '_askResult'", vars.get(0).getName());
}
List<String> line = parser.parse1();
if (line.size() != 1) {
throw new ARQException("CSV Boolean Results malformed: data line='" + line + "'");
}
String str = line.get(0);
boolean b;
if (str.equalsIgnoreCase("true") || str.equalsIgnoreCase("yes"))
b = true;
else if (str.equalsIgnoreCase("false") || str.equalsIgnoreCase("no"))
b = false;
else {
throw new ARQException("CSV Boolean Results malformed, expected one of - true yes false no - but got " + str);
}
List<String> line2 = parser.parse1();
if (line2 != null) {
FmtLog.warn(log, "Extra rows: first is " + line2);
}
return b;
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class CSVOutput method format.
@Override
public void format(OutputStream out, ResultSet resultSet) {
try {
Writer w = FileUtils.asUTF8(out);
NodeToLabelMap bnodes = new NodeToLabelMap();
w = new BufferedWriter(w);
String sep = null;
List<String> varNames = resultSet.getResultVars();
List<Var> vars = new ArrayList<>(varNames.size());
// Convert to Vars and output the header line.
for (String v : varNames) {
if (sep != null)
w.write(sep);
else
sep = ",";
w.write(csvSafe(v));
vars.add(Var.alloc(v));
}
w.write(NL);
// Data output
for (; resultSet.hasNext(); ) {
sep = null;
Binding b = resultSet.nextBinding();
for (Var v : vars) {
if (sep != null)
w.write(sep);
sep = ",";
Node n = b.get(v);
if (n != null)
output(w, n, bnodes);
}
w.write(NL);
}
w.flush();
} catch (IOException ex) {
throw new ARQException(ex);
}
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class UpdateProcessRemote method execute.
@Override
public void execute() {
// Validation
if (this.getEndpoint() == null)
throw new ARQException("Null endpoint for remote update");
if (this.getUpdateRequest() == null)
throw new ARQException("Null update request for remote update");
// Build endpoint URL
String endpoint = this.getEndpoint();
String querystring = this.getQueryString();
if (querystring != null && !querystring.equals("")) {
endpoint = endpoint.contains("?") ? endpoint + "&" + querystring : endpoint + "?" + querystring;
}
// Execution
String reqStr = this.getUpdateRequest().toString();
HttpOp.execHttpPost(endpoint, WebContent.contentTypeSPARQLUpdate, reqStr, getClient(), getHttpContext());
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class Metadata method read.
// Protect all classloader choosing -- sometimes systems mess with even the system class loader.
private static void read(Properties properties, String resourceName) {
// Armour-plate this - classloaders and using them can be blocked by some environments.
try {
ClassLoader classLoader = null;
try {
classLoader = SystemUtils.chooseClassLoader();
} catch (ARQException ex) {
}
if (classLoader == null) {
try {
classLoader = Metadata.class.getClassLoader();
} catch (ARQException ex) {
}
}
if (classLoader == null) {
Log.error(Metadata.class, "No classloader");
return;
}
InputStream in = classLoader.getResourceAsStream(resourceName);
if (in == null)
// In development, there is no properties file.
return;
try {
properties.loadFromXML(in);
} catch (InvalidPropertiesFormatException ex) {
throw new ARQException("Invalid properties file", ex);
} catch (IOException ex) {
throw new ARQException("Metadata ==> IOException", ex);
}
} catch (Throwable ex) {
Log.error(Metadata.class, "Unexpected Thorwable", ex);
return;
}
}
Aggregations