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

package org.bouncycastle.cms;

import org.bouncycastle.util.io.Streams;
import java.io.OutputStream;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import java.io.File;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;

public class CMSProcessableFile implements CMSTypedData, CMSReadable
{
    private static final int DEFAULT_BUF_SIZE = 32768;
    private final ASN1ObjectIdentifier type;
    private final File file;
    private final int bufSize;
    
    public CMSProcessableFile(final File file) {
        this(file, 32768);
    }
    
    public CMSProcessableFile(final File file, final int n) {
        this(CMSObjectIdentifiers.data, file, n);
    }
    
    public CMSProcessableFile(final ASN1ObjectIdentifier type, final File file, final int bufSize) {
        this.type = type;
        this.file = file;
        this.bufSize = bufSize;
    }
    
    @Override
    public InputStream getInputStream() throws IOException, CMSException {
        return new BufferedInputStream(new FileInputStream(this.file), this.bufSize);
    }
    
    @Override
    public void write(final OutputStream outputStream) throws IOException, CMSException {
        final FileInputStream fileInputStream = new FileInputStream(this.file);
        Streams.pipeAll(fileInputStream, outputStream, this.bufSize);
        fileInputStream.close();
    }
    
    @Override
    public Object getContent() {
        return this.file;
    }
    
    @Override
    public ASN1ObjectIdentifier getContentType() {
        return this.type;
    }
}
