-
- /**
- * PhantomReference that deletes the temp file when the FileBackedOutputStream is garbage collected.
- */
- private static class Cleanup extends FinalizablePhantomReference<FileBackedOutputStream> {
- private final File file;
-
- Cleanup(final FileBackedOutputStream referent, final File file) {
- super(referent, REFERENCE_QUEUE);
- this.file = file;
-
- REFERENCE_CACHE.add(this);
-
- LOG.debug("Added Cleanup for temp file {}", file);
- }
-
- @Override
- public void finalizeReferent() {
- LOG.debug("In finalizeReferent");
-
- if (REFERENCE_CACHE.remove(this)) {
- LOG.debug("finalizeReferent - deleting temp file {}", file);
- deleteFile(file);
- }
- }
- }