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

voidclose(FileReader fr)
close
if (fr != null) {
    try {
        fr.close();
    } catch (IOException e) {
voidclose(FileReader reader, BufferedReader br)
close
try {
    if (reader != null)
        reader.close();
    if (br != null)
        br.close();
} catch (IOException e) {
voidclose(final Closeable resource, final String resourceId)
Close the passed resource and care about possible problems.
if (resource != null) {
    try {
        resource.close();
    } catch (IOException e) {
        throw new RuntimeException(
                "Could not close resource properly for unknown reason (unexpected exception): "
                        + resourceId,
                e);
...
voidclose(final Exception e, final Closeable... objects)
Closes all given Closeable s.
close(e, Arrays.asList(objects));
voidclose(final InputStream anInputStream)
close
try {
    anInputStream.close();
} catch (IOException e) {
    e.printStackTrace();
voidclose(final InputStream is)
Close the input stream quietly consuming any exceptions.
close((Closeable) is);
booleanclose(final InputStream stream)
close - Close an InputStream, catching the IOException and returning a value indicating if the exception was thrown.
boolean result;
try {
    stream.close();
    result = false;
} catch (IOException e) {
    result = true;
return result;
...
voidclose(final InputStream stream)
close
if (stream == null) {
    return;
try {
    stream.close();
} catch (IOException e) {
    e.printStackTrace();
voidclose(final Logger logger, final Closeable... closeables)
Close Closeable resource.
if (closeables == null || closeables.length == 0)
    return;
for (final Closeable c : closeables)
    if (c != null)
        try {
            c.close();
        } catch (final IOException e) {
            if (logger != null && logger.isDebugEnabled())
...
voidclose(final Object stream)
Closes the given stream if it is closeable, or do nothing otherwise.
if (stream instanceof Closeable) {
    ((Closeable) stream).close();