Java Stream Close closeFiles(Closeable... closeables)

Here you can find the source of closeFiles(Closeable... closeables)

Description

Silently closes multiple resources.

License

Apache License

Declaration

public static void closeFiles(Closeable... closeables) 

Method Source Code


//package com.java2s;
/*//from   ww w.  j  a va 2 s.c om
 *  Copyright (C) 2011 Google Inc.
 *
 *  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.
 *  under the License.
 */

import java.io.Closeable;
import java.io.IOException;

public class Main {
    /**
     * Silently closes multiple resources. This method doesn't throw any exception when an error
     * occurs when a resource is being closed.
     */
    public static void closeFiles(Closeable... closeables) {
        for (Closeable closeable : closeables) {
            close(closeable);
        }
    }

    /**
     * Silently closes a resource (i.e: don't throw any exception).
     */
    private static void close(Closeable closeable) {
        if (closeable == null) {
            return;
        }
        try {
            closeable.close();
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
    }
}

Related

  1. closeFile(File file, RandomAccessFile raf)
  2. closeFile(FileWriter fw)
  3. closeFile(final Closeable p_closeable)
  4. closeFile(PrintStream ps)
  5. closeFile(RandomAccessFile file)
  6. closeFileWriter(BufferedWriter bw)
  7. closeFileWriter(FileWriter file)
  8. closeGZipStream(GZIPOutputStream outStream)
  9. closeHTML(String pageTemplate, PrintStream out)