Java InputStream Close close(InputStream input)

Here you can find the source of close(InputStream input)

Description

Unconditionally close an InputStream.

License

Open Source License

Parameter

Parameter Description
input - A (possibly null) InputStream

Declaration

public static boolean close(InputStream input) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    /**//from   w  w w .j  ava 2s  . c  o  m
     * Unconditionally close an <code>OutputStream</code>.
     * <p>
     * Equivalent to {@link java.io.OutputStream#close()}, except any exceptions will be
     * ignored.
     *
     * @param output - A (possibly null) OutputStream
     */
    public static boolean close(OutputStream output) {
        if (null == output)
            return false;
        try {
            output.close();
            return true;
        } catch (IOException ioe) {
            return false;
        }
    }

    /**
     * Unconditionally close an <code>InputStream</code>.
     * <p>
     * Equivalent to {@link java.io.InputStream#close()}, except any exceptions will be
     * ignored.
     *
     * @param input - A (possibly null) InputStream
     */
    public static boolean close(InputStream input) {
        if (null == input)
            return false;
        try {
            input.close();
            return true;
        } catch (IOException ioe) {
            return false;
        }
    }

    /**
     * Unconditionally close an <code>InputStream</code>/<code>OutputStream</code> pair.
     *
     * @param in - A (possibly null) InputStream
     * @param out - A (possibly null) OutputStream
     */
    public static void close(InputStream in, OutputStream out) {
        try {
            if (in != null)
                in.close();
        } catch (Exception ignored) {
        }
        try {
            if (out != null)
                out.close();
        } catch (Exception ignored) {
        }
    }

    /**
     * Unconditionally close an <code>Writer</code>.
     * <p>
     * Equivalent to {@link java.io.Writer#close()}, except any exceptions will be
     * ignored.
     *
     * @param output - A (possibly null) Writer
     */
    public static boolean close(Writer output) {
        if (null == output)
            return false;
        try {
            output.close();
            return true;
        } catch (IOException ioe) {
            return false;
        }
    }

    /**
     * Unconditionally close an <code>Reader</code>.
     * <p>
     * Equivalent to {@link java.io.Reader#close()}, except any exceptions will be
     * ignored.
     *
     * @param input - A (possibly null) Reader
     */
    public static boolean close(Reader input) {
        if (null == input)
            return false;
        try {
            input.close();
            return true;
        } catch (IOException ioe) {
            return false;
        }
    }

    /**
     * Unconditionally close a <code>Reader</code>/<code>Writer</code> pair.
     *
     * @param in - A (possibly null) Reader
     * @param out - A (possibly null) Writer
     */
    public static void close(Reader in, Writer out) {
        try {
            if (in != null)
                in.close();
        } catch (Exception ignored) {
        }
        try {
            if (out != null)
                out.close();
        } catch (Exception ignored) {
        }
    }
}

Related

  1. close(InputStream in)
  2. close(InputStream in)
  3. close(InputStream in)
  4. close(InputStream in, boolean silent)
  5. close(InputStream in, OutputStream out)
  6. close(InputStream inputStream)
  7. close(InputStream inputstream)
  8. close(InputStream inputStream)
  9. close(InputStream is)