cmsprocessablefile.java
来自「sip CMSEnvelopedData」· Java 代码 · 共 57 行
JAVA
57 行
package chapter9;
import java.io.*;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.CMSProcessable;
/**
* CMSProcessable that handles File objects.
*/
public class CMSProcessableFile
implements CMSProcessable
{
private File file;
private static final int BUF_SIZE = 4096;
/**
* Base constructor.
*
* @param file a File object representing the file we want processed.
*/
public CMSProcessableFile(
File file)
{
this.file = file;
}
/**
* Write the contents of the file to the passed in OutputStream
*
* @param out the OutputStream passed in by the CMS API.
*/
public void write(
OutputStream out)
throws IOException, CMSException
{
FileInputStream fIn = new FileInputStream(file);
byte[] buf = new byte[BUF_SIZE];
int count = 0;
while ((count = fIn.read(buf)) > 0)
{
out.write(buf, 0, count);
}
fIn.close();
}
/**
* Return the File object we were created with.
*/
public Object getContent()
{
return file;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?