1 7 8 package java.nio.channels; 9 10 import java.io.*; 11 import java.nio.ByteBuffer ; 12 import java.nio.MappedByteBuffer ; 13 import java.nio.channels.spi.AbstractInterruptibleChannel ; 14 15 16 134 135 public abstract class FileChannel 136 extends AbstractInterruptibleChannel 137 implements ByteChannel , GatheringByteChannel , ScatteringByteChannel 138 { 139 140 143 protected FileChannel() { } 144 145 146 148 156 public abstract int read(ByteBuffer dst) throws IOException; 157 158 167 public abstract long read(ByteBuffer [] dsts, int offset, int length) 168 throws IOException; 169 170 178 public final long read(ByteBuffer [] dsts) throws IOException { 179 return read(dsts, 0, dsts.length); 180 } 181 182 193 public abstract int write(ByteBuffer src) throws IOException; 194 195 207 public abstract long write(ByteBuffer [] srcs, int offset, int length) 208 throws IOException; 209 210 221 public final long write(ByteBuffer [] srcs) throws IOException { 222 return write(srcs, 0, srcs.length); 223 } 224 225 226 228 241 public abstract long position() throws IOException; 242 243 269 public abstract FileChannel position(long newPosition) throws IOException; 270 271 283 public abstract long size() throws IOException; 284 285 312 public abstract FileChannel truncate(long size) throws IOException; 313 314 362 public abstract void force(boolean metaData) throws IOException; 363 364 427 public abstract long transferTo(long position, long count, 428 WritableByteChannel target) 429 throws IOException; 430 431 494 public abstract long transferFrom(ReadableByteChannel src, 495 long position, long count) 496 throws IOException; 497 498 541 public abstract int read(ByteBuffer dst, long position) throws IOException; 542 543 586 public abstract int write(ByteBuffer src, long position) throws IOException; 587 588 589 591 599 public static class MapMode { 600 601 604 public static final MapMode READ_ONLY 605 = new MapMode("READ_ONLY"); 606 607 610 public static final MapMode READ_WRITE 611 = new MapMode("READ_WRITE"); 612 613 616 public static final MapMode PRIVATE 617 = new MapMode("PRIVATE"); 618 619 private final String name; 620 621 private MapMode(String name) { 622 this.name = name; 623 } 624 625 630 public String toString() { 631 return name; 632 } 633 634 } 635 636 722 public abstract MappedByteBuffer map(MapMode mode, 723 long position, long size) 724 throws IOException; 725 726 727 729 818 public abstract FileLock lock(long position, long size, boolean shared) 819 throws IOException; 820 821 864 public final FileLock lock() throws IOException { 865 return lock(0L, Long.MAX_VALUE, false); 866 } 867 868 934 public abstract FileLock tryLock(long position, long size, boolean shared) 935 throws IOException; 936 937 966 public final FileLock tryLock() throws IOException { 967 return tryLock(0L, Long.MAX_VALUE, false); 968 } 969 970 } 971 | Popular Tags |