Java Stream Close closeQuietly(Closeable input, Logger log)

Here you can find the source of closeQuietly(Closeable input, Logger log)

Description

Close I/O object quietly without exception but using external logger for logging errors if any

License

Apache License

Parameter

Parameter Description
input object to close
log external logger to use

Declaration

public static void closeQuietly(Closeable input, Logger log) 

Method Source Code

//package com.java2s;
/**// w  w w . j  a  va2  s.c  om
 *    Copyright 2013 MegaFon
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

import org.slf4j.Logger;
import java.io.Closeable;
import java.io.IOException;

public class Main {
    /**
     * Close I/O object quietly without exception
     *
     * @param input object to close
     */
    public static void closeQuietly(Closeable input) {
        try {
            if (input != null) {
                input.close();
            }
        } catch (IOException ioe) {
            // ignore, do nothing
        }
    }

    /**
     * Close I/O object quietly without exception but using external logger for logging errors if any
     *
     * @param input object to close
     * @param log   external logger to use
     */
    public static void closeQuietly(Closeable input, Logger log) {
        try {
            if (input != null) {
                input.close();
            }
        } catch (IOException ioe) {
            log.warn("'close' invocation exception for resource: " + input.getClass().getName(), ioe);
        }
    }
}

Related

  1. closeProofWriter(Writer out)
  2. closeProtectedStream(final OutputStream outputStream)
  3. closeQietly(ZipFile zipFile)
  4. closeQuietly(@Nullable ObjectInput in)
  5. closeQuietly(BufferedReader br)
  6. closeQuietly(Closeable stream)
  7. closeQuietly(Closeable stream)
  8. closeQuietly(final InputStream in)
  9. closeQuietly(final InputStream inputStream)