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
32 public class DefaultFileRegion implements FileRegion {
33
34 private final FileChannel channel;
35
36
37 private final long originalPosition;
38
39
40 private long position;
41
42
43 private long remainingBytes;
44
45
46
47
48
49
50
51 public DefaultFileRegion(FileChannel channel) throws IOException {
52 this(channel, 0, channel.size());
53 }
54
55
56
57
58
59
60
61
62 public DefaultFileRegion(FileChannel channel, long position, long remainingBytes) {
63 if (channel == null) {
64 throw new IllegalArgumentException("channel can not be null");
65 }
66
67 if (position < 0) {
68 throw new IllegalArgumentException("position may not be less than 0");
69 }
70
71 if (remainingBytes < 0) {
72 throw new IllegalArgumentException("remainingBytes may not be less than 0");
73 }
74
75 this.channel = channel;
76 this.originalPosition = position;
77 this.position = position;
78 this.remainingBytes = remainingBytes;
79 }
80
81
82
83
84 @Override
85 public long getWrittenBytes() {
86 return position - originalPosition;
87 }
88
89
90
91
92 @Override
93 public long getRemainingBytes() {
94 return remainingBytes;
95 }
96
97
98
99
100 @Override
101 public FileChannel getFileChannel() {
102 return channel;
103 }
104
105
106
107
108 @Override
109 public long getPosition() {
110 return position;
111 }
112
113
114
115
116 @Override
117 public void update(long value) {
118 position += value;
119 remainingBytes -= value;
120 }
121
122
123
124
125 @Override
126 public String getFilename() {
127 return null;
128 }
129 }