Class SafeCloseableArray<ACT extends AutoCloseable>

java.lang.Object
io.deephaven.util.SafeCloseableArray<ACT>
All Implemented Interfaces:
SafeCloseable, AutoCloseable

public class SafeCloseableArray<ACT extends AutoCloseable> extends Object implements SafeCloseable
SafeCloseable that will close non-null values inside an array.

The common use case is to create an array; use the SafeCloseableArray in an ignored try-with-resources variable, and then populate the array within the loop. If the operation fails before populating the array nothing is closed. If the operation fails during or after populating the array the populated values are closed.

  • Constructor Details

    • SafeCloseableArray

      public SafeCloseableArray(ACT[] entries)
  • Method Details

    • close

      public final void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SafeCloseable
    • close

      public static <ACT extends AutoCloseable> void close(ACT @NotNull [] array)
      Close an array of AutoCloseable entries, ignoring null elements and assigning elements to null as they are cleared.
      Parameters:
      array - The array to operate one