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(Closeable io, Logger logger)
close
try {
    if (io != null) {
        io.close();
} catch (IOException e) {
    if (logger != null) {
        logger.log(Level.SEVERE, e.getMessage(), e);
voidclose(Closeable resource)
Close the given I/O resource.
if (resource != null) {
    try {
        resource.close();
    } catch (IOException e) {
        System.err.println("Closing resource failed!");
        e.printStackTrace();
IOExceptionclose(Closeable resource)
Check if the given resource is not null and then close it, whereby any caught IOException is been returned instead of thrown, so that the caller can if necessary handle (log) or just ignore it without the need to put another try-catch.
if (resource != null) {
    try {
        resource.close();
    } catch (IOException e) {
        return e;
return null;
...
booleanclose(Closeable resource)
close
boolean result = false;
if (resource != null) {
    try {
        resource.close();
        result = true;
    } catch (Exception e) {
return result;
voidclose(Closeable resource, File file)
Close the given I/O resource of the given file.
if (resource != null) {
    try {
        resource.close();
    } catch (IOException e) {
        String message = "Closing file " + file.getPath() + " failed.";
        e.printStackTrace();
voidclose(Closeable stream)
close
if (stream == null) {
    return;
try {
    stream.close();
} catch (IOException ioe) {
voidclose(Closeable... streams)
Closes the specified streams, suppressing any IOExceptions for inputstreams and readers.
close(streams, 0);
voidclose(Collection inCloseables)
close
if (inCloseables != null) {
    for (final Closeable closeable : inCloseables) {
        close(closeable);
voidclose(DataOutputStream out)
close
if (out != null) {
    try {
        out.close();
    } catch (IOException ignored) {
booleanclose(File file)
Use this to close a File that has been opened by this Application
if (file != null) {
    try {
        final FileInputStream fis = new FileInputStream(file);
        fis.getChannel().close();
        return true;
    } catch (IOException ioe) {
        return false;
return false;