Example usage for java.io Closeable close

List of usage examples for java.io Closeable close

Introduction

In this page you can find the example usage for java.io Closeable close.

Prototype

public void close() throws IOException;

Source Link

Document

Closes this stream and releases any system resources associated with it.

Usage

From source file:org.apache.stratos.autoscaler.service.impl.AutoscalerServiceImpl.java

private void closeStream(Closeable stream) {
    if (stream != null) {
        try {//from w  w  w. j a  va 2s.  c  o  m
            stream.close();
        } catch (IOException e) {
            log.error(" Exception is occurred when closing stream. Reason :" + e.getMessage());
        }
    }
}

From source file:edu.dfci.cccb.mev.domain.Heatmap.java

@Override
public void close() throws IOException {
    log.debug("Closing " + this);
    limmaRows.invalidateAll();/*from   w w  w .j  av a2 s . c o m*/
    limmaRows.cleanUp();
    limmaColumns.invalidateAll();
    limmaColumns.cleanUp();
    for (Closeable resource : new ArrayList<Closeable>() {
        private static final long serialVersionUID = 1L;

        {
            add(rowAnnotations);
            add(columnAnnotations);
            if (data instanceof Closeable)
                add((Closeable) data);
        }
    })
        try {
            resource.close();
        } catch (Throwable e) {
            log.warn("Unable to close " + resource + " for " + this, e);
        }
}

From source file:org.georchestra.security.Proxy.java

private IOException close(Closeable stream, IOException... previousExceptions) {
    try {/* www.  j  a  v a2s . co m*/
        if (stream != null) {
            stream.close();
        }
    } catch (IOException e) {
        if (previousExceptions.length > 0) {
            return previousExceptions[0];
        }
        return e;
    }
    if (previousExceptions.length > 0) {
        return previousExceptions[0];
    }
    return null;
}

From source file:org.apache.nifi.remote.util.SiteToSiteRestApiClient.java

private void closeSilently(final Closeable closeable) {
    try {//from w ww.j  a va2  s  .co m
        if (closeable != null) {
            closeable.close();
        }
    } catch (final IOException e) {
        logger.warn("Got an exception when closing {}: {}", closeable, e.getMessage());
        if (logger.isDebugEnabled()) {
            logger.warn("", e);
        }
    }
}

From source file:org.openmrs.util.OpenmrsUtil.java

/**
 * A null-safe and exception safe way to close an inputstream or an outputstream
 * // www . j  a v a  2 s.co m
 * @param closableStream an InputStream or OutputStream to close
 */
public static void closeStream(Closeable closableStream) {
    if (closableStream != null) {
        try {
            closableStream.close();
        } catch (IOException io) {
            log.trace("Error occurred while closing stream", io);
        }
    }
}

From source file:com.dell.asm.asmcore.asmmanager.util.ServiceTemplateUtil.java

/**
 * Utility method to close the input/output stream
 *
 * @param cs/* w w  w  .j  a va2 s .c  o  m*/
 */
public static void closeStreamQuitely(Closeable cs) {
    try {
        if (cs != null) {
            cs.close();
        }
    } catch (Exception e) {
        LOGGER.info("Can't close Stream");
    }
}

From source file:com.enioka.jqm.api.HibernateClient.java

private void closeQuietly(Closeable closeable) {
    try {//from  w  w  w  .  j  ava 2  s .c om
        if (closeable != null) {
            closeable.close();
        }
    } catch (IOException ioe) {
        // ignore
    }
}

From source file:com.tomagoyaky.jdwp.IOUtils.java

/**
 * Closes a <code>Closeable</code> unconditionally.
 * <p/>/*w  w  w  . ja va  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/>
 * <pre>
 * Closeable closeable = null;
 * try {
 *     closeable = new FileReader(&quot;foo.txt&quot;);
 *     // process closeable
 *     closeable.close();
 * } catch (Exception e) {
 *     // error handling
 * } finally {
 *     IOUtils.closeQuietly(closeable);
 * }
 * </pre>
 * <p/>
 * Closing all streams:
 * <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) {
        // ignore
    }
}

From source file:org.paxml.core.Context.java

public void closeAllCloseables() {
    List<Closeable> list = (List) getInternalObject(PrivateKeys.CLOSEABLES, true);
    if (list != null) {
        for (Iterator<Closeable> it = list.iterator(); it.hasNext();) {
            Closeable c = it.next();
            try {
                if (c instanceof Flushable) {
                    ((Flushable) c).flush();
                }//ww w  .  j a  v a  2 s  . c  o m
            } catch (IOException e) {
                // do nothing because it could be already closed.
            } finally {
                try {
                    c.close();
                    it.remove();
                } catch (Exception e) {
                    // say nothing about it because it could be already
                    // closed
                    // by anything else
                }
            }
        }
    }
}