📄 mappedbuffer.java
字号:
package mpjdev.buffertest;
import mpjdev.*;
import mpjbuf.*;
import java.util.Arrays;
import java.nio.*;
import java.nio.channels.FileChannel.*;
import java.nio.channels.*;
import java.io.*;
public class MappedBuffer {
public MappedBuffer() {
}
public MappedBuffer(String[] args) throws Exception {
int DATA_SIZE = 100;
File f = new File("mappedfile1");
RandomAccessFile raf = new RandomAccessFile(f, "rw");
FileChannel fileChannel = raf.getChannel();
MappedByteBuffer mappedByteBuffer =
fileChannel.map(MapMode.READ_WRITE, 0, 400);//f.length());
MPJDev.init(args);
int intArray[] = new int[DATA_SIZE];
for(int k=1 ; k<2; k++) {
for (int i = 0; i < DATA_SIZE; i++) {
intArray[i] = 8;
}
if (MPJDev.WORLD.id() == 0) {
for(int i=0 ; i< DATA_SIZE ; i++) {
mappedByteBuffer.putInt(intArray[i]);
}
//mappedByteBuffer.flip();
} else if ( MPJDev.WORLD.id() == 1 ) {
/* Just make sure that this reads when the data is in there */
try { Thread.currentThread().sleep(1000); }catch(Exception e){}
int intReadArray[] = new int[DATA_SIZE];
for (int i = 0; i < DATA_SIZE; i++) {
intReadArray[i] = 9;
}
for(int i=0 ; i< DATA_SIZE ; i++) {
intReadArray[i] = mappedByteBuffer.getInt();
}
if (Arrays.equals(intArray, intReadArray)) {
System.out.println("\n#################" +
"\n <<<<PASSED>>>> " +
"\n################");
} else {
System.out.println("\n#################" +
"\n <<<<FAILED>>>> " +
"\n################");
}
}
}
try {
Thread.currentThread().sleep(10000);
}
catch (Exception e) {e.printStackTrace(); }
raf.close();
//f.close();
fileChannel.close();
MPJDev.finish();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -