Java Stream Close close(final Object stream)

Here you can find the source of close(final Object stream)

Description

Closes the given stream if it is closeable, or do nothing otherwise.

License

Open Source License

Parameter

Parameter Description
stream The object to close if it is closeable.

Exception

Parameter Description
IOException If an error occurred while closing the stream.

Declaration

public static void close(final Object stream) throws IOException 

Method Source Code


//package com.java2s;
/*//ww  w . j a v  a  2  s  .c om
 *    Geotoolkit.org - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *    (C) 2008-2012, Open Source Geospatial Foundation (OSGeo)
 *    (C) 2009-2012, Geomatys
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

import java.io.*;

public class Main {
    /**
     * Closes the given stream if it is closeable, or do nothing otherwise. Closeable
     * objects are any instance of {@link Closeable}.
     *
     * @param  stream The object to close if it is closeable.
     * @throws IOException If an error occurred while closing the stream.
     *
     * @since 3.07
     */
    public static void close(final Object stream) throws IOException {
        if (stream instanceof Closeable) {
            ((Closeable) stream).close();
        }
        // On JDK6, we needed an explicit check for ImageInputStream.
        // Since JDK7, this is not needed anymore.
    }
}

Related

  1. close(final InputStream anInputStream)
  2. close(final InputStream is)
  3. close(final InputStream stream)
  4. close(final InputStream stream)
  5. close(final Logger logger, final Closeable... closeables)
  6. close(final OutputStream dest)
  7. close(final Scanner scanner)
  8. close(Iterator iterator)
  9. close(java.io.Closeable in)