Java Stream Close closeQuietly(InputStream is)

Here you can find the source of closeQuietly(InputStream is)

Description

Performs the same function as the commons io version but also performs logging of streams which threw an exception when trying to close them and logs them at error level

License

Apache License

Declaration

public static void closeQuietly(InputStream is) 

Method Source Code

//package com.java2s;
/*//from ww  w .j a  v  a  2  s . c om
 * Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
 * Copyright [2016-2018] EMBL-European Bioinformatics Institute
 * 
 * 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 java.io.Closeable;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;

import java.io.Writer;

public class Main {
    /**
     * Performs the same function as the commons io version but also performs
     * logging of readers which threw an exception when trying to close them and
     * logs them at error level
     */
    public static void closeQuietly(Reader reader) {
        close(reader);
    }

    /**
     * Equivalent of {@link #closeQuietly(Writer)} but for {@link Writer}
     * extending classes
     */
    public static void closeQuietly(Writer writer) {
        close(writer);
    }

    /**
     * Performs the same function as the commons io version but also performs
     * logging of streams which threw an exception when trying to close them and
     * logs them at error level
     */
    public static void closeQuietly(InputStream is) {
        close(is);
    }

    /**
     * Equivalent of {@link #closeQuietly(InputStream)} but for
     * {@link OutputStream} extending classes
     */
    public static void closeQuietly(OutputStream os) {
        close(os);
    }

    public static void close(Closeable closeable) {
        if (null != closeable) {
            try {
                closeable.close();
            } catch (IOException e) {
                // don't log error
            }
        }
    }
}

Related

  1. closeQuietly(InputStream input)
  2. closeQuietly(InputStream input)
  3. closeQuietly(InputStream input)
  4. closeQuietly(InputStream inputstream)
  5. closeQuietly(InputStream is)
  6. closeQuietly(InputStream is)
  7. closeQuietly(InputStream is)
  8. closeQuietly(InputStream is)
  9. closeQuietly(InputStream is)