Android Stream Close safeClose(OutputStream os)

Here you can find the source of safeClose(OutputStream os)

Description

Close object safely

Parameter

Parameter Description
os OutputStream

Declaration

// //////////////////////////////////////////////////////
public static void safeClose(OutputStream os) 

Method Source Code

//package com.java2s;
import java.io.*;

public class Main {
    /**/* w w  w  . j  ava 2 s.c o m*/
     * Close object safely
     * 
     * @param is
     *            InputStream
     */
    // //////////////////////////////////////////////////////
    public static void safeClose(InputStream is) {
        try {
            if (is != null)
                is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Close object safely
     * 
     * @param os
     *            OutputStream
     */
    // //////////////////////////////////////////////////////
    public static void safeClose(OutputStream os) {
        try {
            if (os != null)
                os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Close object safely
     * 
     * @param fl
     *            RandomAccessFile
     */
    // //////////////////////////////////////////////////////
    public static void safeClose(RandomAccessFile fl) {
        try {
            if (fl != null)
                fl.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. closeQuietly(Closeable closeable)
  2. closeQuitely(Closeable c)
  3. closeStream(Closeable stream)
  4. closeStream(Closeable stream)
  5. closeStreams(List streams)