// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.tsp.ers;

import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
import org.bouncycastle.operator.DigestCalculator;
import java.io.FileNotFoundException;
import java.io.File;

public class ERSFileData extends ERSCachingData
{
    private final File content;
    
    public ERSFileData(final File content) throws FileNotFoundException {
        if (content.isDirectory()) {
            throw new IllegalArgumentException("directory not allowed as ERSFileData");
        }
        if (!content.exists()) {
            throw new FileNotFoundException(content.getAbsolutePath() + " does not exist");
        }
        if (!content.canRead()) {
            throw new FileNotFoundException(content.getAbsolutePath() + " is not readable");
        }
        this.content = content;
    }
    
    @Override
    protected byte[] calculateHash(final DigestCalculator digestCalculator, final byte[] array) {
        try {
            final FileInputStream fileInputStream = new FileInputStream(this.content);
            final byte[] calculateDigest = ERSUtil.calculateDigest(digestCalculator, fileInputStream);
            fileInputStream.close();
            if (array != null) {
                return ERSUtil.concatPreviousHashes(digestCalculator, array, calculateDigest);
            }
            return calculateDigest;
        }
        catch (final IOException ex) {
            throw new IllegalStateException("unable to process " + this.content.getAbsolutePath());
        }
    }
}
