Java Stream Close closeSilently(OutputStream outputStream)

Here you can find the source of closeSilently(OutputStream outputStream)

Description

Closes the OutputStream, ignoring any exceptions raised while closing.

License

Open Source License

Parameter

Parameter Description
outputStream Stream to close.

Declaration

public static void closeSilently(OutputStream outputStream) 

Method Source Code


//package com.java2s;
//License from project: MIT License 

import java.io.IOException;
import java.io.OutputStream;

public class Main {
    /**//from   w  w  w  .j  a v  a 2 s  .c om
     * Closes the <code>OutputStream</code>, ignoring any exceptions raised while closing. Flushes the stream before closing it.
     *
     * @param outputStream Stream to close.
     */
    public static void closeSilently(OutputStream outputStream) {
        flushSilently(outputStream);
        try {
            outputStream.close();
        } catch (IOException ignored) {
        }
    }

    /**
     * Flushes the <code>OutputStream</code>, ignoring any exceptions raised while closing.
     *
     * @param outputStream Stream to flush.
     */
    public static void flushSilently(OutputStream outputStream) {
        try {
            outputStream.flush();
        } catch (IOException ignored) {
        }
    }
}

Related

  1. closeSilently(InputStream in)
  2. closeSilently(InputStream inputStream)
  3. closeSilently(InputStream... inputStreams)
  4. closeSilently(java.util.logging.Logger log, Closeable stream)
  5. closeSilently(Object obj, Closeable stream)
  6. closeStatusFile(PrintWriter pwStatusFile)
  7. closeStream(Closeable aStream)
  8. closeStream(Closeable closeable)
  9. closeStream(Closeable closeable)