Java Stream Close close(OutputStream in)

Here you can find the source of close(OutputStream in)

Description

Just a convenience method to avoid littering code with if's and catches

License

Apache License

Parameter

Parameter Description
in a parameter

Declaration

public static void close(OutputStream in) 

Method Source Code

//package com.java2s;
/*/*from  w w  w. ja v a2s . c o  m*/
 * Copyright 2010 Thedwick, LLC
    
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
    
 http://www.apache.org/licenses/LICENSE-2.0
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
    
 */

import java.io.OutputStream;
import java.io.Writer;

public class Main {
    /** 
     * Just a convenience method to avoid littering code with if's and catches
     * @param in
     */
    public static void close(OutputStream in) {
        try {
            if (in != null) {
                in.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** 
     * Just a convenience method to avoid littering code with if's and catches
     * @param in
     */
    public static void close(Writer in) {
        try {
            if (in != null) {
                in.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

Related

  1. close(java.io.Closeable in)
  2. close(JMXConnector connector)
  3. close(Object obj)
  4. close(Object resource)
  5. close(ObjectInput in)
  6. close(OutputStream os)
  7. close(OutputStream s)
  8. close(PrintStream writer)
  9. close(Process process)