1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.core.file;
21
22 import java.io.IOException;
23 import java.nio.channels.FileChannel;
24
25
26
27
28
29
30
31 public class DefaultFileRegion implements FileRegion {
32
33 private final FileChannel channel;
34
35 private final long originalPosition;
36
37 private long position;
38
39 private long remainingBytes;
40
41 public DefaultFileRegion(FileChannel channel) throws IOException {
42 this(channel, 0, channel.size());
43 }
44
45 public DefaultFileRegion(FileChannel channel, long position, long remainingBytes) {
46 if (channel == null) {
47 throw new IllegalArgumentException("channel can not be null");
48 }
49
50 if (position < 0) {
51 throw new IllegalArgumentException("position may not be less than 0");
52 }
53
54 if (remainingBytes < 0) {
55 throw new IllegalArgumentException("remainingBytes may not be less than 0");
56 }
57
58 this.channel = channel;
59 this.originalPosition = position;
60 this.position = position;
61 this.remainingBytes = remainingBytes;
62 }
63
64 public long getWrittenBytes() {
65 return position - originalPosition;
66 }
67
68 public long getRemainingBytes() {
69 return remainingBytes;
70 }
71
72 public FileChannel getFileChannel() {
73 return channel;
74 }
75
76 public long getPosition() {
77 return position;
78 }
79
80 public void update(long value) {
81 position += value;
82 remainingBytes -= value;
83 }
84
85 public String getFilename() {
86 return null;
87 }
88
89 }