List of usage examples for java.io Closeable close
public void close() throws IOException;
From source file:org.hyperic.hq.stats.AbstractStatsWriter.java
public static void gzipFile(final String filename) { new Thread() { public void run() { FileOutputStream gfile = null; GZIPOutputStream gstream = null; PrintStream pstream = null; BufferedReader reader = null; boolean succeed = false; try { gfile = new FileOutputStream(filename + ".gz"); gstream = new GZIPOutputStream(gfile); pstream = new PrintStream(gstream); reader = new BufferedReader(new FileReader(filename)); String tmp;/*from w w w . j av a2s. co m*/ while (null != (tmp = reader.readLine())) { pstream.append(tmp).append("\n"); } gstream.finish(); succeed = true; } catch (IOException e) { log.warn(e.getMessage(), e); } finally { close(gfile); close(gstream); close(pstream); close(reader); if (succeed) { new File(filename).delete(); } else { new File(filename + ".gz").delete(); } } } private void close(Closeable s) { if (s != null) { try { s.close(); } catch (IOException e) { log.warn(e.getMessage(), e); } } } }.start(); }
From source file:org.apache.sysml.runtime.io.IOUtilFunctions.java
public static void closeSilently(Closeable io) { try {//from www. ja va2 s. com if (io != null) io.close(); } catch (Exception ex) { LOG.error("Failed to close IO resource.", ex); } }
From source file:divconq.util.IOUtil.java
public static void closeQuietly(Closeable... closeables) { if (closeables == null) return;//from w w w. ja va 2 s . c o m for (Closeable closeable : closeables) { try { if (closeable != null) closeable.close(); } catch (IOException x) { // ignore } } }
From source file:org.kontalk.util.SystemUtils.java
/** Closes the given stream, ignoring any errors. */ public static void closeStream(Closeable stream) { try {/*from w ww. j av a 2s .com*/ stream.close(); } catch (Exception ignored) { } }
From source file:org.wso2.carbon.ml.decomposition.spark.SparkDecompositionServiceUtil.java
/** * Utility method for closing resources. * * @param resource Represents closeable resources * @throws DecompositionException/*w w w.j ava2 s. c o m*/ */ private static void closeResource(Closeable resource) throws DecompositionException { if (resource == null) { return; } try { resource.close(); } catch (IOException ex) { throw new DecompositionException("An error occurred while closing the resource: " + ex.getMessage(), ex); } }
From source file:net.dorokhov.pony.web.server.common.StreamingViewRenderer.java
/** * Close the given resource.//from w ww .j a v a 2s. c om * @param resource The resource to be closed. */ private static void close(Closeable resource) { if (resource != null) { try { resource.close(); } catch (IOException ignore) { // Ignore IOException. If you want to handle this anyway, it might be useful to know // that this will generally only be thrown when the client aborted the request. } } }
From source file:com.swingtech.apps.filemgmt.controller.StreamingViewRenderer.java
/** * Close the given resource./*w w w .j av a 2s . com*/ * * @param resource * The resource to be closed. */ private static void close(Closeable resource) { if (resource != null) { try { resource.close(); } catch (IOException ignore) { // Ignore IOException. If you want to handle this anyway, it // might be useful to know // that this will generally only be thrown when the client // aborted the request. } } }
From source file:com.lrs.enviroment.Metadata.java
private static void closeQuietly(Closeable c) { if (c != null) { try {/*from ww w .j a v a2 s . c o m*/ c.close(); } catch (Exception ignored) { // ignored } } }
From source file:org.rhq.enterprise.server.sync.ExportingInputStream.java
private static void safeClose(Closeable str) { try {/* w w w .j av a 2 s.c om*/ if (str != null) { str.close(); } } catch (IOException e) { LOG.error("Failed to close an output stream. This shouldn't happen.", e); } }
From source file:com.puppycrawl.tools.checkstyle.utils.CommonUtils.java
/** * Closes a stream re-throwing IOException as IllegalStateException. * * @param closeable//from w w w . jav a 2 s . c o m * Closeable object */ public static void close(Closeable closeable) { if (closeable == null) { return; } try { closeable.close(); } catch (IOException e) { throw new IllegalStateException("Cannot close the stream", e); } }