org.bouncycastle.cms.CMSProcessableFile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcmail-jdk16 Show documentation
Show all versions of bcmail-jdk16 Show documentation
The Bouncy Castle Java CMS and S/MIME APIs for handling the CMS and S/MIME protocols. This jar contains CMS and S/MIME APIs for JDK 1.6. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs. If the S/MIME API is used, the JavaMail API and the Java activation framework will also be needed.
package org.bouncycastle.cms;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* a holding class for a file of data to be processed.
*/
public class CMSProcessableFile
implements CMSProcessable
{
private static final int DEFAULT_BUF_SIZE = 32 * 1024;
private final File _file;
private final byte[] _buf;
public CMSProcessableFile(
File file)
{
this(file, DEFAULT_BUF_SIZE);
}
public CMSProcessableFile(
File file,
int bufSize)
{
_file = file;
_buf = new byte[bufSize];
}
public void write(OutputStream zOut)
throws IOException, CMSException
{
FileInputStream fIn = new FileInputStream(_file);
int len;
while ((len = fIn.read(_buf, 0, _buf.length)) > 0)
{
zOut.write(_buf, 0, len);
}
fIn.close();
}
/**
* Return the file handle.
*/
public Object getContent()
{
return _file;
}
}