Here you can find the source of close(Closeable... streams)
Parameter | Description |
---|---|
streams | the streams to close |
Parameter | Description |
---|
public static void close(Closeable... streams) throws IOException
//package com.java2s; import java.io.Closeable; import java.io.Flushable; import java.io.IOException; import java.io.InputStream; import java.io.Reader; public class Main { /**/*ww w. jav a2 s . c o m*/ * Closes the specified streams, suppressing any IOExceptions for inputstreams and readers. * Even if an I/O exception is thrown, all streams can be considered closed. * @param streams the streams to close * @throws java.io.IOException if an i/o exception occurs while closing any outputstream or writer */ public static void close(Closeable... streams) throws IOException { close(streams, 0); } private static void close(Closeable[] streams, int idx) throws IOException { if (idx >= streams.length) { return; // done } Closeable stream = streams[idx]; try { if (stream != null) { if (stream instanceof Flushable) { ((Flushable) stream).flush(); } stream.close(); } } catch (IOException ex) { if (!(stream instanceof InputStream || stream instanceof Reader)) { throw ex; // ignore io exceptions for input streams and readers } } finally { close(streams, idx + 1); } } }