List of usage examples for java.io Closeable close
public void close() throws IOException;
From source file:guru.benson.pinch.Pinch.java
/** * Handy close method to avoid nestled try/catch blocks. * * @param c// w ww . j av a 2 s. c o m * The object to close. */ private static void close(Closeable c) { if (c != null) { try { c.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.yccheok.jstock.file.Utils.java
/** * Performs close operation on Closeable stream, without the need of * writing cumbersome try...catch block. * * @param closeable The closeable stream. *//* www . j ava2 s . c o m*/ public static void close(Closeable closeable) { // Instead of returning boolean, we will just simply swallow any // exception silently. This is because this method will usually be // invoked within finally block. If we are having control statement // (return, break, continue) within finally block, a lot of surprise may // happen. // http://stackoverflow.com/questions/48088/returning-from-a-finally-block-in-java if (null != closeable) { try { closeable.close(); } catch (IOException ex) { log.error(null, ex); } } }
From source file:net.sf.jasperreports.eclipse.util.FileUtils.java
public static void closeStream(Closeable stream) { if (stream != null) try {/*from www .j av a2 s . c o m*/ stream.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.baomidou.mybatisplus.toolkit.IOUtils.java
/** * Closes a <code>Closeable</code> unconditionally. * <p>/*from w w w . ja v a 2s.c o m*/ * Equivalent to {@link Closeable#close()}, except any exceptions will be ignored. This is typically used in finally * blocks. * <p> * Example code: * </p> * <p> * <pre> * Closeable closeable = null; * try { * closeable = new FileReader("foo.txt"); * // process closeable * closeable.close(); * } catch (Exception e) { * // error handling * } finally { * IOUtils.closeQuietly(closeable); * } * </pre> * <p> * Closing all streams: * </p> * <p> * <pre> * try { * return IOUtils.copy(inputStream, outputStream); * } finally { * IOUtils.closeQuietly(inputStream); * IOUtils.closeQuietly(outputStream); * } * </pre> * * @param closeable the objects to close, may be null or already closed * @since 2.0 */ public static void closeQuietly(final Closeable closeable) { try { if (closeable != null) { closeable.close(); } } catch (final IOException ioe) { logger.error("error close io", ioe); } }
From source file:org.wso2.carbon.analytics.data.commons.utils.AnalyticsCommonUtils.java
public static void closeQuietly(Closeable closeable) { try {/*w w w. j a v a 2s . co m*/ if (closeable != null) { closeable.close(); } } catch (IOException ignore) { /* ignore */ } }
From source file:org.dhatim.util.ClassUtil.java
private static void close(final Closeable closable) { if (closable != null) { try {//from w w w.j av a 2s. com closable.close(); } catch (IOException e) { logger.debug("Exception while trying to close : " + closable, e); } } }
From source file:com.attribyte.essem.util.Util.java
/** * Close without throwing an exception./*from w ww. java 2 s. co m*/ * @param c The closable. */ public static void closeQuietly(final Closeable c) { if (c != null) { try { c.close(); } catch (IOException ioe) { //Ignore... } } }
From source file:org.mhisoft.common.util.FileUtils.java
private static void close(Closeable closable) { if (closable != null) { try {//from w w w .java 2s . c o m closable.close(); } catch (IOException e) { // } } }
From source file:ubicrypt.core.Utils.java
public static void close(final Closeable... closeables) { for (final Closeable closeable : closeables) { try {//ww w .j a v a2 s . c om if (closeable != null) { closeable.close(); } } catch (final Exception e) { } } }
From source file:org.opendaylight.vtn.manager.it.option.TestOption.java
/** * Close the given closeable.//from ww w .ja va2s. c o m * * @param c A {@link Closeable} to be closed. */ private static void close(Closeable c) { if (c != null) { try { c.close(); } catch (IOException e) { throw new IllegalStateException("close() failed: " + c, e); } } }