public static BufferedReader readerFromURL( String urlStr ) { try { return asBufferedUTF8( new URL(urlStr).openStream() ); } catch (java.net.MalformedURLException e) { // Try as a plain filename. try { return asBufferedUTF8( new FileInputStream( urlStr ) ); } catch (FileNotFoundException f) { throw new WrappedIOException( f ); } } catch (IOException e) { throw new WrappedIOException( e ); } }
/** Answer the list of rules loaded from the given filename. May throw a ReasonerException wrapping an IOException. */ public static List<Rule> loadRules( String fileName ) { try { return Rule.parseRules(Util.loadRuleParserFromResourceFile( fileName ) ); } catch (WrappedIOException e) { throw new ReasonerException("Can't load rules file: " + fileName, e.getCause() ); } }
@Override public Model read( String url, String base, String lang ) { try { InputStream is = new URL( url ) .openStream(); try { read( is, base, lang ); } finally { if (null != is) { is.close(); } } } catch (IOException e) { throw new WrappedIOException( e ); } return this; }
/** Answer a BufferedReader than reads from the named resource file as UTF-8, possibly throwing WrappedIOExceptions. */ public static BufferedReader openResourceFile( String filename ) { try { InputStream is = FileUtils.openResourceFileAsStream( filename ); return new BufferedReader(new InputStreamReader(is, "UTF-8")); } catch (IOException e) { throw new WrappedIOException( e ); } }
/** 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); } r.close(); sw.close(); return sw.toString(); } catch (IOException ex) { throw new WrappedIOException(ex) ; } }
/** * Load the <code>velocity.properties</code> file from the Velocity root, if it exists. * @param velocityPath One or more Velocity root directories to look in * @param p Properties to instantiate */ protected void loadPropertiesFile( List<String> velocityPath, Properties p ) { for (String velocityRoot: velocityPath) { InputStream is = EldaFileManager.get().open( velocityRoot + VELOCITY_PROPERTIES_FILE ); if (is != null) { try { p.load( is ); } catch (IOException e) { log.warn( "IO exception while reading properties: {} ({})", e.getMessage(), e); throw new WrappedIOException( e ); } finally { try { is.close(); } catch (IOException e) { log.warn("IO exception while closing properties input stream: {} ({})", e.getMessage(), e); throw new WrappedIOException( e ); } } // stop after we find the first velocity.properties break; } } }
{ throw new WrappedIOException( e ); }
synchronized private 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; } }