Java Stream Close closeQuietly(Closeable stream)

Here you can find the source of closeQuietly(Closeable stream)

Description

Close a stream, ignores checked Exceptions and nulls, but rethrows RuntimeExceptions.

License

Apache License

Parameter

Parameter Description
stream the object to close

Declaration

public static void closeQuietly(Closeable stream) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.slf4j.LoggerFactory;
import java.io.Closeable;

public class Main {
    private static final org.slf4j.Logger logger = LoggerFactory.getLogger("intercom-java");

    /**/* w w w.  ja va 2s . c o  m*/
     * Close a stream, ignores checked Exceptions and nulls,
     * but rethrows RuntimeExceptions.
     *
     * @param stream the object to close
     */
    public static void closeQuietly(Closeable stream) {
        if (stream != null) {
            try {
                stream.close();
            } catch (RuntimeException rethrow) {
                throw rethrow;
            } catch (Exception e) {
                logger.warn(e.getMessage());
            }
        }
    }
}

Related

  1. closeProtectedStream(final OutputStream outputStream)
  2. closeQietly(ZipFile zipFile)
  3. closeQuietly(@Nullable ObjectInput in)
  4. closeQuietly(BufferedReader br)
  5. closeQuietly(Closeable input, Logger log)
  6. closeQuietly(Closeable stream)
  7. closeQuietly(final InputStream in)
  8. closeQuietly(final InputStream inputStream)
  9. closeQuietly(final Reader reader)