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