com.bluecatcode.common.io.CloseableReference Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Standard library extensions
The newest version!
package com.bluecatcode.common.io;
import javax.annotation.Nullable;
import java.io.Closeable;
import java.io.IOException;
public class CloseableReference implements Closeable {
private final T reference;
private final Closer closer;
public CloseableReference(@Nullable T reference, Closer closer) {
this.reference = reference;
if (closer == null) {
throw new IllegalArgumentException("Expected closer to be non-null");
}
this.closer = closer;
}
public T get() {
return reference;
}
@Override
public void close() throws IOException {
try {
if (reference != null) {
closer.close(reference);
}
} catch (Exception e) {
throw new IOException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy