01: package org.apache.mina.common;
02:
03: import java.nio.channels.FileChannel;
04:
05: public class DefaultFileRegion implements FileRegion {
06:
07: private final FileChannel channel;
08:
09: private long originalPosition;
10: private long position;
11: private long count;
12:
13: public DefaultFileRegion(FileChannel channel, long position,
14: long count) {
15: if (channel == null) {
16: throw new IllegalArgumentException(
17: "channel can not be null");
18: }
19: if (position < 0) {
20: throw new IllegalArgumentException(
21: "position may not be less than 0");
22: }
23: if (count < 0) {
24: throw new IllegalArgumentException(
25: "count may not be less than 0");
26: }
27: this .channel = channel;
28: this .originalPosition = position;
29: this .position = position;
30: this .count = count;
31: }
32:
33: public long getWrittenBytes() {
34: return position - originalPosition;
35: }
36:
37: public long getCount() {
38: return count;
39: }
40:
41: public FileChannel getFileChannel() {
42: return channel;
43: }
44:
45: public long getPosition() {
46: return position;
47: }
48:
49: public void setPosition(long value) {
50: if (value < position) {
51: throw new IllegalArgumentException(
52: "New position value may not be less than old position value");
53: }
54: count -= value - position;
55: position = value;
56: }
57:
58: }
|