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

voidcloseQuietly(InputStream is)
Closes the stream, if possible, suppressing any exception.
if (is != null) {
    try {
        is.close();
    } catch (Exception e) {
voidcloseQuietly(InputStream is)
close Quietly
try {
    if (is != null) {
        is.close();
} catch (Exception e) {
voidcloseQuietly(InputStream is)
Closes the given input stream without throwing an exception.
if (null != is) {
    try {
        is.close();
    } catch (IOException e) {
voidcloseQuietly(InputStream stream)
Quietly close a given stream, suppressing exceptions.
if (stream == null) {
    return;
try {
    stream.close();
} catch (IOException e) {
voidcloseQuietly(InputStream x)
Unconditionally close an InputStream.
if (x == null) {
    return;
try {
    x.close();
} catch (IOException e) {
    interruptIfNecessary(e);
voidcloseQuietly(java.io.Closeable writer)
close Quietly
try {
    if (writer != null) {
        writer.close();
} catch (IOException ioe) {
voidcloseQuietly(Object input)
close Quietly
if (input == null || !(input instanceof Closeable)) {
    return;
try {
    ((Closeable) input).close();
} catch (IOException ioe) {
voidcloseQuietly(Object obj)
close Quietly
if (obj != null) {
    if (obj instanceof Closeable) {
        try {
            ((Closeable) obj).close();
        } catch (Exception e) {
    } else {
        throw new ClassCastException("Not a closable Object");
...
voidcloseQuietly(Object object)
If the specified object is an InputStream or OutputStream, then it is closed and any exceptions are ignored.
try {
    if (object instanceof InputStream) {
        ((InputStream) object).close();
    } else if (object instanceof OutputStream) {
        ((OutputStream) object).close();
} catch (Exception e) {
voidcloseQuietly(Object object)
close Quietly
if (object != null) {
    try {
        if (object instanceof Closeable) {
            ((Closeable) object).close();
        } else if (object instanceof InputStream) {
            ((InputStream) object).close();
        } else if (object instanceof OutputStream) {
            ((OutputStream) object).close();
...