Class Closeables

java.lang.Object
org.newsclub.net.unix.Closeables
All Implemented Interfaces:
Closeable, AutoCloseable

public final class Closeables extends Object implements Closeable
A set of Closeables that can be closed at once.
Author:
Christian Kohlschütter
  • Constructor Details

    • Closeables

      public Closeables()
      Creates a new Closeables instance.
    • Closeables

      public Closeables(Closeable... closeable)
      Creates a new Closeables instance, populating it with the given Closeable objects.
      Parameters:
      closeable - The Closeables to add.
  • Method Details

    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • close

      public void close(IOException superException) throws IOException
      Closes all registered closeables.
      Parameters:
      superException - If set, any exceptions thrown in here will be chained to the given exception via addSuppressed, and then thrown.
      Throws:
      IOException - if an exception occurs.
    • add

      public boolean add(WeakReference<Closeable> closeable)
      Adds the given closeable, but only using a weak reference.
      Parameters:
      closeable - The closeable.
      Returns:
      true iff the closeable was added, false if it was null or already added before.
    • add

      public boolean add(Closeable closeable)
      Adds the given closeable.
      Parameters:
      closeable - The closeable.
      Returns:
      true iff the closeable was added, false if it was null or already added before.
    • remove

      public boolean remove(Closeable closeable)
      Removes the given closeable.
      Parameters:
      closeable - The closeable.
      Returns:
      true iff the closeable was removed, fale if it was null or not previously added.