@Override protected void destroyTarget(OutputStream target) { Lang.closeQuietly(target); }
/** * Initializes the JDK logger and loads the configuration file from the specified stream. * * @throws Exception * Thrown on any error. */ private void initializeJUL(InputStream logConfig) throws Exception { Lang.denyNull("log configuration stream", logConfig); try { LogManager.getLogManager() .readConfiguration(logConfig); } catch (Exception e) { throw e; } finally { Lang.closeQuietly(logConfig); } }
private void closeAllRequestedStreamsOnDemand() { if (closeTrackedStreams()) { Iterator<WeakReference<InputStreamWrapper>> iterator = inputStreamList.iterator(); while (iterator.hasNext()) { WeakReference<InputStreamWrapper> reference = iterator.next(); InputStreamWrapper stream = reference.get(); Lang.closeQuietly(stream); stream = null; System.gc(); } } }
Lang.closeQuietly(inputStream);
static List<String> getClassNames(URL url) throws LimbusClasspathException { Lang.denyNull("URL", url); ZipInputStream inputStream = null; try { List<String> classNames = new ArrayList<String>(); URLConnection connection = url.openConnection(); inputStream = new ZipInputStream(connection.getInputStream()); for (ZipEntry entry = inputStream.getNextEntry(); entry != null; entry = inputStream.getNextEntry()) { if (!entry.isDirectory() && entry.getName() .endsWith(".class")) { // This ZipEntry represents a class. Now, what class does it represent? String className = entry.getName() .replace('/', '.'); // including ".class" classNames.add(className.substring(0, className.length() - ".class".length())); } inputStream.closeEntry(); } return classNames; } catch (Exception e) { throw new LimbusClasspathException("Cannot scan the contents of " + url.toString(), e); } finally { Lang.closeQuietly(inputStream); } }
/** * Constructs a System Engine that reads the system descriptor from the specified input stream. * * @param descriptorInput * The input stream containing the XML system descriptor. * @throws SerializeException * Thrown if the Limbus System cannot be deserialized. */ public SystemEngine(InputStream descriptorInput) throws SerializeException { Lang.denyNull("descriptorInput", descriptorInput); try { this.system = fromInputStream(descriptorInput); } finally { Lang.closeQuietly(descriptorInput); } }