Java Stream Close close(OutputStream s)

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

Description

Call close on an output stream and ignore any exception.

License

Open Source License

Parameter

Parameter Description
s the stream to call .close() on

Return

OuputStream null

Declaration

public static OutputStream close(OutputStream s) 

Method Source Code


//package com.java2s;
/*/*w w w.  j a v a2s.c  o m*/
 * ? Copyright IBM Corp. 2012-2013
 * 
 * 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.IOException;
import java.io.InputStream;

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

public class Main {
    /**
     * Call close on an output stream and ignore any exception.
     * @param s the stream to call .close() on
     * @return OuputStream null
     * @ibm-api
     */
    public static OutputStream close(OutputStream s) {
        if (s != null) {
            try {
                s.close();
            } catch (IOException ioe) {
                /** ignore */
            }
        }
        return null;
    }

    /**
     * Call close on an input stream and ignore any exception.
     * @param s the stream to call .close() on
     * @return InputStream null
     * @ibm-api
     */
    public static InputStream close(InputStream s) {
        if (s != null) {
            try {
                s.close();
            } catch (IOException ioe) {
                /** ignore */
            }
        }
        return null;
    }

    /**
     * Call close on a Writer and ignore any exception.
     * @param s the Writer to call .close() on
     * @return Writer null
     * @ibm-api
     */
    public static Writer close(Writer w) {
        if (w != null) {
            try {
                w.close();
            } catch (IOException ioe) {
                /** ignore */
            }
        }
        return null;
    }

    /**
     * Call close on a Reader and ignore any exception.
     * @param s the Reader to call .close() on
     * @return Reader null
     * @ibm-api
     */
    public static Reader close(Reader r) {
        if (r != null) {
            try {
                r.close();
            } catch (IOException ioe) {
                /** ignore */
            }
        }
        return null;
    }
}

Related

  1. close(Object obj)
  2. close(Object resource)
  3. close(ObjectInput in)
  4. close(OutputStream in)
  5. close(OutputStream os)
  6. close(PrintStream writer)
  7. close(Process process)
  8. close(RandomAccessFile randomAccessFile)
  9. close(Writer out)