Java Utililty Methods Stream Close

List of utility methods to do Stream Close

Description

The list of methods to do Stream Close are organized into topic(s).

Method

voidcloseStream(OutputStream os)
Closes an output stream
try {
    os.close();
} catch (Exception e) {
voidcloseStreamIgnoreExpection(InputStream stream)
close Stream Ignore Expection
try {
    if (stream != null) {
        stream.close();
} catch (Exception e) {
voidcloseStreamQuietly(final Closeable closeable)
Close quietly an object which implements the Closeable interface such as InputStream, OutputStream, Reader ...
try {
    if (closeable != null)
        closeable.close();
} catch (IOException ioe) {
voidcloseStreams(FileInputStream fis, FileOutputStream fos)
close Streams
try {
    if (fis != null) {
        fis.close();
} finally {
    if (fos != null) {
        fos.close();
voidcloseStreams(InputStream iStream, OutputStream oStream)
close Streams
if (iStream != null) {
    try {
        iStream.close();
    } catch (IOException e) {
        e.printStackTrace();
if (oStream != null) {
...
voidcloseStreams(InputStream src, OutputStream dest)
Closes the streams and reports Exceptions to System.err
try {
    src.close();
} catch (IOException e) {
    e.printStackTrace();
try {
    dest.close();
} catch (IOException e) {
...
voidcloseStreams(Process process)
close Streams
try {
    process.getInputStream().close();
    process.getOutputStream().close();
    process.getErrorStream().close();
} catch (IOException e) {
    e.printStackTrace();
InputStreamcloseUnchecked(InputStream stream)
close Unchecked
try {
    stream.close();
    return stream;
} catch (IOException e) {
    throw new RuntimeException(e);
booleancloseWarnOnError(Closeable stream, Logger log, String message)
close Warn On Error
if (stream != null) {
    try {
        stream.close();
    } catch (IOException e) {
        if (message == null)
            message = "Error while attempting to close";
        log.log(Level.WARNING, message + ": ", e);
        return false;
...
voidcloseWhileHandlingException(Closeable... objects)
Closes all given Closeables, suppressing all thrown exceptions.
closeWhileHandlingException(Arrays.asList(objects));