01: package org.jvnet.mimepull;
02:
03: import java.nio.ByteBuffer;
04:
05: /**
06: * Keeps the Part's partial content data in a file.
07: *
08: * @author Kohsuke Kawaguchi
09: * @author Jitendra Kotamraju
10: */
11: final class FileData implements Data {
12: private final DataFile file;
13: private final long pointer; // read position
14: private final int length;
15:
16: FileData(DataFile file, ByteBuffer buf) {
17: this (file, file.writeTo(buf.array(), 0, buf.limit()), buf
18: .limit());
19: }
20:
21: FileData(DataFile file, long pointer, int length) {
22: this .file = file;
23: this .pointer = pointer;
24: this .length = length;
25: }
26:
27: public byte[] read() {
28: byte[] buf = new byte[length];
29: file.read(pointer, buf, 0, length);
30: return buf;
31: }
32:
33: /*
34: * This shouldn't be called
35: */
36: public long writeTo(DataFile file) {
37: throw new UnsupportedOperationException();
38: }
39:
40: public int size() {
41: return length;
42: }
43:
44: /*
45: * Always create FileData
46: */
47: public Data createNext(DataHead dataHead, ByteBuffer buf) {
48: return new FileData(file, buf);
49: }
50: }
|