Java Stream Close closeQuietly(Object object)

Here you can find the source of closeQuietly(Object object)

Description

If the specified object is an InputStream or OutputStream, then it is closed and any exceptions are ignored.

License

Open Source License

Parameter

Parameter Description
object the object to close

Declaration

public static void closeQuietly(Object object) 

Method Source Code

//package com.java2s;
/*==========================================================================*\
 |  $Id: FileUtilities.java,v 1.5 2014/06/16 15:59:40 stedwar2 Exp $
 |*-------------------------------------------------------------------------*|
 |  Copyright (C) 2006-2012 Virginia Tech
 |
 |  This file is part of Web-CAT./*  w ww.j  a  v  a 2s.  c o m*/
 |
 |  Web-CAT is free software; you can redistribute it and/or modify
 |  it under the terms of the GNU Affero General Public License as published
 |  by the Free Software Foundation; either version 3 of the License, or
 |  (at your option) any later version.
 |
 |  Web-CAT 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 Affero General Public License
 |  along with Web-CAT; if not, see <http://www.gnu.org/licenses/>.
\*==========================================================================*/

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

public class Main {
    /**
     * If the specified object is an InputStream or OutputStream, then it is
     * closed and any exceptions are ignored. Otherwise, this method does
     * nothing.
     *
     * @param object the object to close
     */
    public static void closeQuietly(Object object) {
        try {
            if (object instanceof InputStream) {
                ((InputStream) object).close();
            } else if (object instanceof OutputStream) {
                ((OutputStream) object).close();
            }
        } catch (Exception e) {
            // Do nothing.
        }
    }
}

Related

  1. closeQuietly(InputStream stream)
  2. closeQuietly(InputStream x)
  3. closeQuietly(java.io.Closeable writer)
  4. closeQuietly(Object input)
  5. closeQuietly(Object obj)
  6. closeQuietly(Object object)
  7. closeQuietly(Object... o)
  8. closeQuietly(ObjectInput objectInput)
  9. closeQuietly(ObjectInput... objectInputs)