Java Stream Close closeInputStream(InputStream in)

Here you can find the source of closeInputStream(InputStream in)

Description

Closes an input stream.

License

GNU General Public License

Parameter

Parameter Description
in The stream to close.

Return

null unless an exception was thrown while closing, else returns the stream

Declaration

public static InputStream closeInputStream(InputStream in) 

Method Source Code


//package com.java2s;
/*/*from  w w  w.  j a v  a  2 s.  c  om*/
 * Cobertura - http://cobertura.sourceforge.net/
 *
 * Copyright (C) 2005 Grzegorz Lukasik
 * Copyright (C) 2006 John Lewis
 * Copyright (C) 2007 Ignat Zapolsky
 *
 * Note: This file is dual licensed under the GPL and the Apache
 * Source License (so that it can be used from both the main
 * Cobertura classes and the ant tasks).
 *
 * Cobertura 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.
 *
 * Cobertura 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 Cobertura; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

import java.io.*;

public class Main {
    /**
     * Closes an input stream.
     *
     * @param in The stream to close.
     *
     * @return null unless an exception was thrown while closing, else
     *         returns the stream
     */
    public static InputStream closeInputStream(InputStream in) {
        if (in != null) {
            try {
                in.close();
                in = null;
            } catch (IOException e) {
                System.err.println("Cobertura: Error closing input stream.");
                e.printStackTrace();
            }
        }
        return in;
    }
}

Related

  1. closeIgnoringExceptions(Closeable c)
  2. closeImage()
  3. closeIncludeGuard(String name, PrintWriter writer)
  4. closeInput(InputStream src)
  5. closeInputStream(DataInputStream di)
  6. closeInputStream(InputStream inp)
  7. closeInputStream(InputStream inputStream)
  8. closeInputStream(InputStream inputStream)
  9. closeInputStream(InputStream stream)