Java Stream Close close(final InputStream stream)

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

Description

close - Close an InputStream, catching the IOException and returning a value indicating if the exception was thrown.

License

Open Source License

Parameter

Parameter Description
stream The InputStream to close

Return

A value indicating if the IOException was thrown

Declaration

public static boolean close(final InputStream stream) 

Method Source Code


//package com.java2s;
/*/*from  w  w w . jav a 2 s .  c om*/
 * $Id: StreamUtil.java,v 1.1 2006-08-21 03:07:12 dave Exp $
 *
 * iNamik Template Engine
 * Copyright (C) 2006 David Farrell (davidpfarrell@yahoo.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

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

public class Main {
    /**
     * close - Close an InputStream, catching the IOException and
     * returning a value indicating if the exception was thrown.
     *
     * @param stream The InputStream to close
     * @return A value indicating if the IOException was thrown
     */
    public static boolean close(final InputStream stream) {
        boolean result;

        try {
            stream.close();
            result = false;
        } catch (IOException e) {
            result = true;
        }

        return result;
    }

    /**
     * close - Close an OutputStream, catching the IOException and
     * returning a value indicating if the exception was thrown.
     *
     * @param stream The InputStream to close
     * @return A value indicating if the IOException was thrown
     */
    public static boolean close(final OutputStream stream) {
        boolean result;

        try {
            stream.close();
            result = false;
        } catch (IOException e) {
            result = true;
        }

        return result;
    }
}

Related

  1. close(final Closeable resource, final String resourceId)
  2. close(final Exception e, final Closeable... objects)
  3. close(final InputStream anInputStream)
  4. close(final InputStream is)
  5. close(final InputStream stream)
  6. close(final Logger logger, final Closeable... closeables)
  7. close(final Object stream)
  8. close(final OutputStream dest)
  9. close(final Scanner scanner)