/** * Check whether container supports opening a stream on a dir/package to get a list of its contents. */ private static boolean supportsDirStream(URL packageURL) { InputStream is = null; try { is = packageURL.openStream(); return true; } catch (FileNotFoundException ex) { return false; } catch (IOException ex) { return false; } finally { InternalUtils.close(is); } }
/** * Check whether container supports opening a stream on a dir/package to get a list of its contents. */ private static boolean supportsDirStream(URL packageURL) { InputStream is = null; try { is = packageURL.openStream(); return true; } catch (FileNotFoundException ex) { return false; } catch (IOException ex) { return false; } finally { InternalUtils.close(is); } }
private void writeExceptionToFile(Throwable exception, File log) throws IOException { log.createNewFile(); PrintWriter writer = null; try { writer = new PrintWriter(log); exceptionReportWriter.writeReport(writer, exception); } finally { InternalUtils.close(writer); } }
@Override protected InputStream doMinimize(StreamableResource resource) throws IOException { StringWriter writer = new StringWriter(1000); Reader reader = new InputStreamReader(resource.openStream()); try { new CssCompressor(reader).compress(writer, -1); writer.flush(); return IOUtils.toInputStream(writer.getBuffer()); } finally { InternalUtils.close(reader); InternalUtils.close(writer); } } }
@Override protected InputStream doMinimize(StreamableResource resource) throws IOException { StringWriter writer = new StringWriter(1000); Reader reader = new InputStreamReader(resource.openStream()); try { new CssCompressor(reader).compress(writer, -1); writer.flush(); return IOUtils.toInputStream(writer.getBuffer()); } finally { InternalUtils.close(reader); InternalUtils.close(writer); } } }
private void readProperties() { Properties p = new Properties(); InputStream is = null; try { is = resource.openStream(); p.load(is); is.close(); is = null; for (Map.Entry<Object, Object> entry : p.entrySet()) { String key = entry.getKey().toString(); properties.put(key, p.getProperty(key)); } } catch (IOException ex) { throw new RuntimeException(ex); } finally { InternalUtils.close(is); } }
private void readProperties() { Properties p = new Properties(); InputStream is = null; try { is = resource.openStream(); p.load(is); is.close(); is = null; for (Map.Entry<Object, Object> entry : p.entrySet()) { String key = entry.getKey().toString(); properties.put(key, p.getProperty(key)); } } catch (IOException ex) { throw new RuntimeException(ex); } finally { InternalUtils.close(is); } }
public List<TapestryPersistenceUnitInfo> parse(final InputStream stream) { final PersistenceContentHandler handler = new PersistenceContentHandler(); try { final XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setContentHandler(handler); reader.parse(new InputSource(stream)); return handler.getPersistenceUnits(); } catch (final Exception e) { throw new RuntimeException(e); } finally { InternalUtils.close(stream); } }
public List<TapestryPersistenceUnitInfo> parse(final InputStream stream) { final PersistenceContentHandler handler = new PersistenceContentHandler(); try { final XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setContentHandler(handler); reader.parse(new InputSource(stream)); return handler.getPersistenceUnits(); } catch (final Exception e) { throw new RuntimeException(e); } finally { InternalUtils.close(stream); } }
@Override public void run() { InputStream in = null; Reader r = null; try { in = script.openStream(); r = new InputStreamReader(in, StandardCharsets.UTF_8); context.evaluateReader(scope, r, script.toString(), 1, null); } catch (IOException ex) { throw new RuntimeException(String.format("Unable to read script %s: %s", script, ExceptionUtils.toMessage(ex) ), ex); } finally { InternalUtils.close(r); InternalUtils.close(in); } } });
@Override public void run() { InputStream in = null; Reader r = null; try { in = script.openStream(); r = new InputStreamReader(in, "UTF-8"); context.evaluateReader(scope, r, script.toString(), 1, null); } catch (IOException ex) { throw new RuntimeException(String.format("Unable to read script %s: %s", script, ExceptionUtils.toMessage(ex) ), ex); } finally { InternalUtils.close(r); InternalUtils.close(in); } } });
public Map<String, String> parsePropertiesFile(Resource resource) throws IOException { Map<String, String> result = CollectionFactory.newCaseInsensitiveMap(); Properties p = new Properties(); InputStream is = null; try { is = readUTFStreamToEscapedASCII(resource.openStream()); // Ok, now we have the content read into memory as UTF-8, not ASCII. p.load(is); is.close(); is = null; } finally { InternalUtils.close(is); } for (Map.Entry e : p.entrySet()) { String key = e.getKey().toString(); String value = p.getProperty(key); result.put(key, value); } return result; }
@Override public String getContent() throws FileNotFound, CannotReadFile { // Adapted from Less's URLSource Reader input = null; try { input = new InputStreamReader(resource.openStream()); String content = IOUtils.toString(input).replace("\r\n", "\n"); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } }
@Override public String getContent() throws FileNotFound, CannotReadFile { // Adapted from Less's URLSource Reader input = null; try { input = new InputStreamReader(resource.openStream()); String content = IOUtils.toString(input).replace("\r\n", "\n"); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { Reader input = null; try { input = new InputStreamReader(resource.openStream()); return IOUtils.toByteArray(input); } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } } }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { Reader input = null; try { input = new InputStreamReader(resource.openStream()); return IOUtils.toByteArray(input); } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } } }
} finally InternalUtils.close(is);
content = IOUtils.toString(is, UTF8); } finally { InternalUtils.close(is);
private List<TapestryPersistenceUnitInfo> parsePersistenceUnitInfos(Resource persistenceDescriptor) { List<TapestryPersistenceUnitInfo> persistenceUnitInfos = CollectionFactory.newList(); if (persistenceDescriptor.exists()) { final PersistenceParser parser = new PersistenceParser(); InputStream inputStream = null; try { inputStream = persistenceDescriptor.openStream(); persistenceUnitInfos = parser.parse(inputStream); } catch (Exception e) { throw new RuntimeException(e); } finally { InternalUtils.close(inputStream); } } return persistenceUnitInfos; }
private List<TapestryPersistenceUnitInfo> parsePersistenceUnitInfos(Resource persistenceDescriptor) { List<TapestryPersistenceUnitInfo> persistenceUnitInfos = CollectionFactory.newList(); if (persistenceDescriptor.exists()) { final PersistenceParser parser = new PersistenceParser(); InputStream inputStream = null; try { inputStream = persistenceDescriptor.openStream(); persistenceUnitInfos = parser.parse(inputStream); } catch (Exception e) { throw new RuntimeException(e); } finally { InternalUtils.close(inputStream); } } return persistenceUnitInfos; }