本文整理匯總了Java中java.nio.channels.FileChannel.MapMode.READ_WRITE屬性的典型用法代碼示例。如果您正苦於以下問題:Java MapMode.READ_WRITE屬性的具體用法?Java MapMode.READ_WRITE怎麽用?Java MapMode.READ_WRITE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.nio.channels.FileChannel.MapMode
的用法示例。
在下文中一共展示了MapMode.READ_WRITE屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: open
public void open(MapMode mode, int fileSize) throws IOException {
int fileLength = (int)this.file.length();
int size = (mode == MapMode.READ_WRITE) ? fileSize : fileLength;
this.mmf = new MemoryMappedFile(this.file, size, mode == MapMode.READ_WRITE ? "rw" : "r");
if (mode == MapMode.READ_WRITE) {
File parent = file.getAbsoluteFile().getParentFile();
long free = parent.getUsableSpace();
if ((fileSize * 4) > free) {
throw new HumpbackException("out of storage space: " + this.file.toString() + ' ' + free);
}
}
if (mode == MapMode.READ_WRITE) {
this.mmf.buf.load();
}
this.mmf.buf.order(ByteOrder.LITTLE_ENDIAN);
this.addr = this.mmf.getAddress();
this.spStart = SpaceManager.makeSpacePointer(this.id, 0);
this.spEnd = fileSize + this.spStart;
this.allocPointer = new AtomicInteger(fileLength);
this.capacity = this.mmf.buf.capacity();
}
示例2: MemoryMappedFile
public MemoryMappedFile(File file, String mode, long offset, long size) throws IOException {
if (size >= Integer.MAX_VALUE) {
throw new IllegalArgumentException("jvm doesn't support mapped file more than 2g");
}
MapMode mapmode = null;
if (mode.equals("r")) {
mapmode = MapMode.READ_ONLY;
}
else if (mode.equals("rw")) {
mapmode = MapMode.READ_WRITE;
}
else {
throw new IllegalArgumentException();
}
if ((mapmode == MapMode.READ_WRITE) && !file.exists()) {
File parent = file.getAbsoluteFile().getParentFile();
long free = parent.getUsableSpace();
if ((size * 4) > free) {
throw new HumpbackException("out of storage space: " + file.toString() + ' ' + free);
}
}
this.file = file;
boolean exist = this.file.exists();
this.raf = new RandomAccessFile(file, mode);
this.channel = raf.getChannel();
this.buf = channel.map(mapmode, offset, size);
this.buf.order(ByteOrder.nativeOrder());
this.addr = UberUtil.getAddress(buf);
_log.debug(String.format("mounted %s %s %s at 0x%016x with length 0x%08x",
exist ? "exist" : "new",
file.toString(),
mode,
addr,
size));
}