ManagedRandomAccessFileByteReader.java 1.19 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.internal.io.RandomAccessFileByteReader
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemfd.pdfdocmanager.internal.io;

import com.adobe.internal.io.RandomAccessFileByteReader;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ManagedRandomAccessFileByteReader
extends RandomAccessFileByteReader {
    private static final Logger logger = LoggerFactory.getLogger(ManagedRandomAccessFileByteReader.class);
    private File sourceFile;
    private boolean closed = false;

    public ManagedRandomAccessFileByteReader(RandomAccessFile file, File sourceFile) {
        super(file);
        this.sourceFile = sourceFile;
    }

    public void close() throws IOException {
        if (this.closed) {
            return;
        }
        super.close();
        String path = this.sourceFile.getAbsolutePath();
        if (!this.sourceFile.delete()) {
            logger.warn("Failed to delete managed file at location " + path);
        }
        this.sourceFile = null;
        this.closed = true;
    }
}