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.camel.util.IOHelper.java

/**
 * Closes the given resource if it is available, logging any closing
 * exceptions to the given log/*from www  .ja  v a 2s . c o  m*/
 *
 * @param closeable the object to close
 * @param name the name of the resource
 * @param log the log to use when reporting closure warnings
 */
public static void close(Closeable closeable, String name, Log log) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (IOException e) {
            if (log != null) {
                if (name != null) {
                    log.warn("Cannot close: " + name + ". Reason: " + e.getMessage(), e);
                } else {
                    log.warn("Cannot close. Reason: " + e.getMessage(), e);
                }
            }
        }
    }
}

From source file:se.vgregion.domain.infrastructure.webservice.RestCalendarEventsRepository.java

private static void closeClosables(Closeable... closables) {
    for (Closeable closeable : closables) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
                LOGGER.error(e.getMessage(), e);
            }//from   w  w  w  .  j a v  a2  s . com
        }
    }
}

From source file:org.brekka.stillingar.spring.snapshot.ResourceSnapshotManager.java

/**
 * Close the steams/*from   w ww . ja  v  a  2 s . com*/
 */
private static void closeQuietly(Closeable closeable) {
    try {
        if (closeable != null) {
            closeable.close();
        }
    } catch (IOException ioe) {
        // Ignore
    }
}

From source file:com.fizzed.blaze.util.Streamables.java

static private Runnable asUncheckedRunnable(Closeable c) {
    return () -> {
        try {//from   w w  w .ja  v  a  2  s. c  o  m
            c.close();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    };
}

From source file:org.srlutils.Files.java

public static void tryClose(Closeable door) {
    try {//from w w w . j ava2  s  . c  o m
        door.close();
    } catch (Exception ex) {
    }
}

From source file:Main.java

public static void closeSilently(final Closeable c) {
    if (c == null)
        return;/*  w  w w. j a va  2  s . c  om*/
    try {
        c.close();
    } catch (final Throwable t) {
    }
}

From source file:org.srlutils.Files.java

/** close door, wrapping any exceptions as runtime exceptions */
public static void rteClose(Closeable door) {
    try {/*w  w  w.  ja  v a 2  s. com*/
        door.close();
    } catch (Exception ex) {
        throw rte(ex, "close failed for closeable: '%s'", door);
    }
}

From source file:org.flowerplatform.communication.public_resources.PublicResourcesServlet.java

private static void close(Closeable resource) {
    if (resource != null) {
        try {//from w  w w .j  a  va  2s .co  m
            resource.close();
        } catch (IOException e) {
            // Do nothing.
        }
    }
}

From source file:ja.centre.util.io.Files.java

public static void close(Closeable closable) throws IOException {
    if (closable != null) {
        closable.close();
    }//from  w  ww. j a v  a  2 s  .  co  m
}

From source file:eu.stratosphere.nephele.util.IOUtils.java

/**
 * Close the Closeable objects and <b>ignore</b> any {@link IOException} or
 * null pointers. Must only be used for cleanup in exception handlers.
 * /* w  w w  .  ja v a  2 s .c  o  m*/
 * @param log
 *        the log to record problems to at debug level. Can be <code>null</code>.
 * @param closeables
 *        the objects to close
 */
public static void cleanup(final Log log, final java.io.Closeable... closeables) {
    for (java.io.Closeable c : closeables) {
        if (c != null) {
            try {
                c.close();
            } catch (IOException e) {
                if (log != null && log.isDebugEnabled()) {
                    log.debug("Exception in closing " + c, e);
                }
            }
        }
    }
}