01: package org.bouncycastle.cms;
02:
03: import java.io.File;
04: import java.io.FileInputStream;
05: import java.io.IOException;
06: import java.io.OutputStream;
07:
08: /**
09: * a holding class for a file of data to be processed.
10: */
11: public class CMSProcessableFile implements CMSProcessable {
12: private static final int DEFAULT_BUF_SIZE = 32 * 1024;
13:
14: private final File _file;
15: private final byte[] _buf;
16:
17: public CMSProcessableFile(File file) {
18: this (file, DEFAULT_BUF_SIZE);
19: }
20:
21: public CMSProcessableFile(File file, int bufSize) {
22: _file = file;
23: _buf = new byte[bufSize];
24: }
25:
26: public void write(OutputStream zOut) throws IOException,
27: CMSException {
28: FileInputStream fIn = new FileInputStream(_file);
29: int len;
30:
31: while ((len = fIn.read(_buf, 0, _buf.length)) > 0) {
32: zOut.write(_buf, 0, len);
33: }
34:
35: fIn.close();
36: }
37:
38: /**
39: * Return the file handle.
40: */
41: public Object getContent() {
42: return _file;
43: }
44: }
|