62,614
社区成员
发帖
与我相关
我的任务
分享
RandomAccessFile raf;
try {
raf = new RandomAccessFile(IncBspConstants.MEMORY_SHARE_FILE+"_part_"+peer.getPeerIndex(), "rw");
FileChannel fc = raf.getChannel();
mbb = fc.map(MapMode.READ_WRITE, 0, bufferSize);
readData() ;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
private void readData(){
try{
int flag = mbb.get() ; //取读写数据的标志
if(mbb==null) LOG.info(" mbb is NULL! " + "flag :" + flag) ;
if(flag!=1)
mbb.clear() ;
else //=1说明已经写入则读取
{
dataLength = mbb.getInt() ;
buf = new byte[dataLength] ;
mbb = (MappedByteBuffer) mbb.get(buf);
}
} catch (Exception e) {
e.printStackTrace();
}
}