Java Stream Close closeOutputStream(OutputStream out, boolean flush)

Here you can find the source of closeOutputStream(OutputStream out, boolean flush)

Description

Close the given output stream if not null

License

Open Source License

Parameter

Parameter Description
out An input stream to close
flush if true - flush the stream before closing

Declaration

public static final void closeOutputStream(OutputStream out,
        boolean flush) 

Method Source Code

//package com.java2s;
/*/*w  w w  . ja v a2s . c  o m*/
 This file is part of Ustad Mobile.

 Ustad Mobile Copyright (C) 2011-2014 UstadMobile Inc.

 Ustad Mobile is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version with the following additional terms:

 All names, links, and logos of Ustad Mobile and Toughra Technologies FZ
 LLC must be kept as they are in the original distribution.  If any new
 screens are added you must include the Ustad Mobile logo as it has been
 used in the original distribution.  You may not create any new
 functionality whose purpose is to diminish or remove the Ustad Mobile
 Logo.  You must leave the Ustad Mobile logo as the logo for the
 application to be used with any launcher (e.g. the mobile app launcher).

 If you want a commercial license to remove the above restriction you must
 contact us.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

 Ustad Mobile is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 */

import java.io.IOException;

import java.io.OutputStream;

public class Main {
    /**
     * Close the given output stream if not null
     * 
     * @param out An input stream to close
     * @param flush if true - flush the stream before closing
     */
    public static final void closeOutputStream(OutputStream out,
            boolean flush) {
        try {
            if (out != null) {
                if (flush)
                    out.flush();
                out.close();
            }
        } catch (IOException e) {

        }
    }

    /**
     * Close the output stream give if not null.  Will not flush the output stream:
     *  e.g. the same as calling closeOutputSteam(out, false)
     * 
     * @param out 
     */
    public static final void closeOutputStream(OutputStream out) {
        closeOutputStream(out, false);
    }
}

Related

  1. closeNoThrow(InputStream s)
  2. closeOutput(OutputStream stream)
  3. closeOutputFile(OutputStream os)
  4. closeOutputFile(Writer pWriter)
  5. closeOutputStream(OutputStream out)
  6. closeOutputStream(OutputStream outputStream)
  7. closePermanentOutputWriter()
  8. closePort()
  9. closePrintWriter(PrintWriter fileOutputStream)