Java Stream Close closeSilently(InputStream in)

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

Description

close Silently

License

Open Source License

Declaration

public static void closeSilently(InputStream in) 

Method Source Code


//package com.java2s;
/* *******************************************************************
 * Copyright (c) 1999-2001 Xerox Corporation, 
 *               2002 Palo Alto Research Center, Incorporated (PARC).
 * All rights reserved. // w ww  .ja  v  a 2 s  . c  o  m
 * This program and the accompanying materials are made available 
 * under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 *  
 * Contributors: 
 *     Xerox/PARC     initial implementation 
 * ******************************************************************/

import java.io.*;

public class Main {
    public static void closeSilently(InputStream in) {
        if (null != in) {
            try {
                in.close();
            } catch (IOException e) {
                // do nothing
            }
        }
    }

    public static void closeSilently(Reader in) {
        if (null != in) {
            try {
                in.close();
            } catch (IOException e) {
                // do nothing
            }
        }
    }

    /**
     * Close stream with the usual checks.
     * @param stream the InputStream to close - ignored if null 
     * @return null if closed without IOException, message otherwise 
     */
    public static String close(Writer stream) {
        String result = null;
        if (null != stream) {
            try {
                stream.close();
            } catch (IOException e) {
                result = e.getMessage();
            }
        }
        return result;
    }
}

Related

  1. closeSafely(final FileOutputStream output)
  2. closeSafely(InputStream is)
  3. closeSafely(ZipInputStream zis)
  4. closeSecurityConfigurationFileInputStream(FileInputStream fis)
  5. closeSilently(final InputStream is)
  6. closeSilently(InputStream inputStream)
  7. closeSilently(InputStream... inputStreams)
  8. closeSilently(java.util.logging.Logger log, Closeable stream)
  9. closeSilently(Object obj, Closeable stream)