- java.lang.Object
-
- com.github.robtimus.filesystems.CleanerSupport
-
public final class CleanerSupport extends Object
A utility class forCleaners.Action for
Cleaners cannot declare any checked exception to be thrown. When usingCleaners with file systems, it's common that the action can throwIOExceptions. The methods in this class allow such exceptions to be wrapped and unwrapped easily. The typical use is to callregister(Cleaner, Object, CleanAction)to createCleaner.Cleanableinstances, andclean(Cleanable)to invoke these instances. This allows anyIOExceptionthrown from the action provided toregister(Cleaner, Object, CleanAction)to be re-thrown whenclean(Cleanable)is called.- Author:
- Rob Spoor
- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCleanerSupport.CleanActionAn action to invoke when objects become phantom reachable.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclean(Cleaner.Cleanable cleanable)Invokes aCleaner.Cleanable, unwrapping anyUncheckedIOExceptionthrown by it.static Cleaner.Cleanableregister(Cleaner cleaner, Object obj, CleanerSupport.CleanAction action)Registers an object and a cleaning action in aCleaner.
-
-
-
Method Detail
-
register
public static Cleaner.Cleanable register(Cleaner cleaner, Object obj, CleanerSupport.CleanAction action)
Registers an object and a cleaning action in aCleaner. This method is a wrapper aroundCleaner.register(Object, Runnable)that allows the action to throwIOExceptions. If the action throws anIOExceptionwhen the returnedCleaner.Cleanableis called, anUncheckedIOExceptionwill be thrown. Useclean(Cleanable)instead of directly callingCleaner.Cleanable.clean()to unwrap that exception.- Parameters:
cleaner- TheCleanerto register the given object and action in.obj- The object to monitor.action- The action to invoke when the object becomes phantom reachable.- Returns:
- A
Cleaner.Cleanableinstance. - Throws:
NullPointerException- If the givenCleaner, object or action isnull.
-
clean
public static void clean(Cleaner.Cleanable cleanable) throws IOException
Invokes aCleaner.Cleanable, unwrapping anyUncheckedIOExceptionthrown by it. Any other unchecked exception will be relayed to the caller.- Parameters:
cleanable- TheCleaner.Cleanableto invoke.- Throws:
NullPointerException- If the givenCleaner.Cleanableisnull.IOException- If the givenCleaner.Cleanablethrows anUncheckedIOException.
-
-