Search in sources :

Example 1 with WrappedIOException

use of org.apache.jena.shared.WrappedIOException in project jena by apache.

the class JenaReader method read.

private synchronized void read(final Graph g, InputSource inputS, String xmlBase, Model m) {
    try {
        g.getEventManager().notifyEvent(g, GraphEvents.startRead);
        inputS.setSystemId(xmlBase);
        handler = new JenaHandler(g, m, errorHandler);
        handler.useWith(arpf.getHandlers());
        arpf.parse(inputS, xmlBase);
    } catch (IOException e) {
        throw new WrappedIOException(e);
    } catch (SAXException e) {
        throw new JenaException(e);
    } finally {
        g.getEventManager().notifyEvent(g, GraphEvents.finishRead);
        handler = null;
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) WrappedIOException(org.apache.jena.shared.WrappedIOException) WrappedIOException(org.apache.jena.shared.WrappedIOException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 2 with WrappedIOException

use of org.apache.jena.shared.WrappedIOException in project jena by apache.

the class FileManagerImpl method readWholeFileAsUTF8.

/**
 * Slurp up a whole file
 */
@Override
public String readWholeFileAsUTF8(InputStream in) {
    try (Reader r = FileUtils.asBufferedUTF8(in);
        StringWriter sw = new StringWriter(1024)) {
        char[] buff = new char[1024];
        while (true) {
            int l = r.read(buff);
            if (l <= 0)
                break;
            sw.write(buff, 0, l);
        }
        return sw.toString();
    } catch (IOException ex) {
        throw new WrappedIOException(ex);
    }
}
Also used : WrappedIOException(org.apache.jena.shared.WrappedIOException) WrappedIOException(org.apache.jena.shared.WrappedIOException)

Example 3 with WrappedIOException

use of org.apache.jena.shared.WrappedIOException in project jena by apache.

the class FileManager method readWholeFileAsUTF8.

/** Slurp up a whole file */
public String readWholeFileAsUTF8(InputStream in) {
    try (Reader r = FileUtils.asBufferedUTF8(in);
        StringWriter sw = new StringWriter(1024)) {
        char[] buff = new char[1024];
        while (true) {
            int l = r.read(buff);
            if (l <= 0)
                break;
            sw.write(buff, 0, l);
        }
        return sw.toString();
    } catch (IOException ex) {
        throw new WrappedIOException(ex);
    }
}
Also used : WrappedIOException(org.apache.jena.shared.WrappedIOException) WrappedIOException(org.apache.jena.shared.WrappedIOException)

Example 4 with WrappedIOException

use of org.apache.jena.shared.WrappedIOException in project jena by apache.

the class Rule method rulesParserFromReader.

/**
 * Processes the source reader stripping off comment lines and noting prefix
 * definitions (@prefix) and rule inclusion commands (@include).
 * Returns a parser which is bound to the stripped source text with
 * associated prefix and rule inclusion definitions.
 */
public static Parser rulesParserFromReader(BufferedReader src, BuiltinRegistry registry) {
    try {
        StringBuilder result = new StringBuilder();
        String line;
        Map<String, String> prefixes = new HashMap<>();
        List<Rule> preloadedRules = new ArrayList<>();
        while ((line = src.readLine()) != null) {
            // Skip comment lines
            if (line.startsWith("#"))
                continue;
            line = line.trim();
            // Skip comment lines
            if (line.startsWith("//"))
                continue;
            if (line.startsWith("@prefix")) {
                line = line.substring("@prefix".length());
                String prefix = nextArg(line);
                String rest = nextAfterArg(line);
                if (prefix.endsWith(":"))
                    prefix = prefix.substring(0, prefix.length() - 1);
                String url = extractURI(rest);
                prefixes.put(prefix, url);
            } else if (line.startsWith("@include")) {
                // Include referenced rule file, either URL or local special case
                line = line.substring("@include".length());
                String url = extractURI(line);
                // Check for predefined cases
                if (url.equalsIgnoreCase("rdfs")) {
                    preloadedRules.addAll(RDFSFBRuleReasoner.loadRules());
                } else if (url.equalsIgnoreCase("owl")) {
                    preloadedRules.addAll(OWLFBRuleReasoner.loadRules());
                } else if (url.equalsIgnoreCase("owlmicro")) {
                    preloadedRules.addAll(OWLMicroReasoner.loadRules());
                } else if (url.equalsIgnoreCase("owlmini")) {
                    preloadedRules.addAll(OWLMiniReasoner.loadRules());
                } else {
                    // Just try loading as a URL
                    preloadedRules.addAll(rulesFromURL(url));
                }
            } else {
                result.append(line);
                result.append("\n");
            }
        }
        Parser parser = new Parser(result.toString(), registry);
        parser.registerPrefixMap(prefixes);
        parser.addRulesPreload(preloadedRules);
        return parser;
    } catch (IOException e) {
        throw new WrappedIOException(e);
    }
}
Also used : WrappedIOException(org.apache.jena.shared.WrappedIOException) WrappedIOException(org.apache.jena.shared.WrappedIOException)

Aggregations

WrappedIOException (org.apache.jena.shared.WrappedIOException)4 IOException (java.io.IOException)1 JenaException (org.apache.jena.shared.JenaException)1 SAXException (org.xml.sax.SAXException)1