java.nio.MappedByteBuffer#capacity ( )源码实例Demo

下面列出了java.nio.MappedByteBuffer#capacity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: SoftwarePilot   文件: BasicRoutine.java
byte[] read4k(){
    	try {
		File file = new File(Environment.getExternalStorageDirectory().getPath()+"/AUAVtmp/fullPic.JPG");
		//File file = new File("../tmp/pictmp.jpg");
		FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
		MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
		pic = new byte[buffer.capacity()];
		while(buffer.hasRemaining()){
	    		int remaining = pic.length;
	    		if(buffer.remaining() < remaining){
				remaining = buffer.remaining();
	    		}
	    		buffer.get(pic, 0, remaining);
		}
		return pic;
    	} catch(Exception e){
		e.printStackTrace();
    	}
    	return new byte[0];
}
 
源代码2 项目: SoftwarePilot   文件: YoloVisionTest.java
byte[] read4k(){
    	try {
		File file = new File(Environment.getExternalStorageDirectory().getPath()+"/AUAVtmp/fullPic.JPG");
		//File file = new File("../tmp/pictmp.jpg");
		FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
		MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
		pic = new byte[buffer.capacity()];
		while(buffer.hasRemaining()){
	    		int remaining = pic.length;
	    		if(buffer.remaining() < remaining){
				remaining = buffer.remaining();
	    		}
	    		buffer.get(pic, 0, remaining);
		}
		return pic;
    	} catch(Exception e){
		e.printStackTrace();
    	}
    	return new byte[0];
}
 
源代码3 项目: SoftwarePilot   文件: AutoSelfie.java
byte[] readImg(){
    try {
        //BufferedImage origImage = ImageIO.read(imgPath);
        //ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //ImageIO.write(origImage, "jpg", baos);
        //return baos.toByteArray();

        File file = new File(Environment.getExternalStorageDirectory().getPath()+"/AUAVtmp/fullPic.JPG");
        //File file = new File("../tmp/pictmp.jpg");
        FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
        MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
        pic = new byte[buffer.capacity()];
        while(buffer.hasRemaining()){
            int remaining = pic.length;
            if(buffer.remaining() < remaining){
                remaining = buffer.remaining();
            }
            buffer.get(pic, 0, remaining);
        }
        return pic;
    } catch(Exception e){
        e.printStackTrace();
    }
    return new byte[0];
}
 
源代码4 项目: SoftwarePilot   文件: WaypointMissionTest.java
byte[] readWaypoint(String fname){
	
      	    	//read in the file
    	try{
   		File f = new File(Environment.getExternalStorageDirectory().getPath()+fname);
		FileChannel fileChannel = new RandomAccessFile(f,"r").getChannel();
		MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY,0,fileChannel.size());
		data = new byte[buffer.capacity()];
		while(buffer.hasRemaining()){
			int remaining = data.length;
			if (buffer.remaining()<remaining){
				remaining = buffer.remaining();
			}
			buffer.get(data,0,remaining);
		}
		return data;
	   }catch (IOException e) {
    	  	e.printStackTrace();   
	   }
	return new byte[0];
}
 
源代码5 项目: SoftwarePilot   文件: WaypointMissionTest.java
byte[] read4k(){
    try {
        File file = new File(Environment.getExternalStorageDirectory().getPath()+"/AUAVtmp/fullPic.JPG");
        //File file = new File("../tmp/pictmp.jpg");
        FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
        MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
        pic = new byte[buffer.capacity()];
        while(buffer.hasRemaining()){
            int remaining = pic.length;
            if(buffer.remaining() < remaining){
                remaining = buffer.remaining();
            }
            buffer.get(pic, 0, remaining);
        }
        return pic;
    } catch(Exception e){
        e.printStackTrace();
    }
    return new byte[0];
}
 
源代码6 项目: SoftwarePilot   文件: WaypointMissionTestBackup.java
byte[] read4k(){
    try {
        File file = new File(Environment.getExternalStorageDirectory().getPath()+"/AUAVtmp/fullPic.JPG");
        //File file = new File("../tmp/pictmp.jpg");
        FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
        MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
        pic = new byte[buffer.capacity()];
        while(buffer.hasRemaining()){
            int remaining = pic.length;
            if(buffer.remaining() < remaining){
                remaining = buffer.remaining();
            }
            buffer.get(pic, 0, remaining);
        }
        return pic;
    } catch(Exception e){
        e.printStackTrace();
    }
    return new byte[0];
}
 
源代码7 项目: SoftwarePilot   文件: RoutineTemplate.java
byte[] read4k(){
    try {
        File file = new File(Environment.getExternalStorageDirectory().getPath()+"/AUAVtmp/fullPic.JPG");
        //File file = new File("../tmp/pictmp.jpg");
        FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
        MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
        pic = new byte[buffer.capacity()];
        while(buffer.hasRemaining()){
            int remaining = pic.length;
            if(buffer.remaining() < remaining){
                remaining = buffer.remaining();
            }
            buffer.get(pic, 0, remaining);
        }
        return pic;
    } catch(Exception e){
        e.printStackTrace();
    }
    return new byte[0];
}
 
源代码8 项目: SoftwarePilot   文件: BasicVision.java
byte[] read4k(){
    try {
        File file = new File(Environment.getExternalStorageDirectory().getPath()+"/AUAVtmp/fullPic.JPG");
        //File file = new File("../tmp/pictmp.jpg");
        FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
        MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
        pic = new byte[buffer.capacity()];
        while(buffer.hasRemaining()){
            int remaining = pic.length;
            if(buffer.remaining() < remaining){
                remaining = buffer.remaining();
            }
            buffer.get(pic, 0, remaining);
        }
        return pic;
    } catch(Exception e){
        e.printStackTrace();
    }
    return new byte[0];
}
 
源代码9 项目: SoftwarePilot   文件: CubeSim.java
byte[] readImg(){
    try {
        //BufferedImage origImage = ImageIO.read(imgPath);
        //ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //ImageIO.write(origImage, "jpg", baos);
        //return baos.toByteArray();

        //File file = new File(Environment.getExternalStorageDirectory().getPath()+"/AUAVtmp/fullPic.JPG");
        File file = new File("../tmp/pictmp.jpg");
        FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
        MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
        byte[] pic = new byte[buffer.capacity()];
        while(buffer.hasRemaining()){
            int remaining = pic.length;
            if(buffer.remaining() < remaining){
                remaining = buffer.remaining();
            }
            buffer.get(pic, 0, remaining);
        }
        return pic;
    } catch(Exception e){
        e.printStackTrace();
    }
    return new byte[0];
}
 
源代码10 项目: SoftwarePilot   文件: VisionTest.java
byte[] readImg(){
    try {
        //BufferedImage origImage = ImageIO.read(imgPath);
        //ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //ImageIO.write(origImage, "jpg", baos);
        //return baos.toByteArray();

        File file = new File(Environment.getExternalStorageDirectory().getPath()+"/AUAVtmp/fullPic.JPG");
        //File file = new File("../tmp/pictmp.jpg");
        FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
        MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
        byte[] pic = new byte[buffer.capacity()];
        while(buffer.hasRemaining()){
            int remaining = pic.length;
            if(buffer.remaining() < remaining){
                remaining = buffer.remaining();
            }
            buffer.get(pic, 0, remaining);
        }
        return pic;
    } catch(Exception e){
        e.printStackTrace();
    }
    return new byte[0];
}
 
源代码11 项目: crail   文件: RdmaStorageLocalEndpoint.java
public RdmaStorageLocalEndpoint(InetSocketAddress datanodeAddr) throws Exception {
	LOG.info("new local endpoint for address " + datanodeAddr);
	String dataPath = RdmaStorageServer.getDatanodeDirectory(datanodeAddr);
	File dataDir = new File(dataPath);
	if (!dataDir.exists()){
		throw new Exception("Local RDMA data path missing");
	}
	this.address = datanodeAddr;
	this.bufferMap = new ConcurrentHashMap<Long, CrailBuffer>();
	this.unsafe = getUnsafe();
	long lba = 0;
	for (File dataFile : dataDir.listFiles()) {
		MappedByteBuffer mappedBuffer = mmap(dataFile);
		bufferMap.put(lba, OffHeapBuffer.wrap(mappedBuffer));
		lba += mappedBuffer.capacity();
	}				
}
 
源代码12 项目: cc-dbp   文件: FileUtil.java
/**
 * get an input stream for the file that is fast, trading memory for speed
 * 
 * @param file
 * @return InputStream
 */
public static InputStream fastStream(File file) {
  FileInputStream fis = null;
  FileChannel ch = null;
  byte[] byteArray = null;
  try {
    fis = new FileInputStream(file);
    if (fis != null) {
      ch = fis.getChannel();
      if (ch.size() > 1000000000) {
      	return new BufferedInputStream(fis, BUFFER_SIZE);
      }
      MappedByteBuffer mb = ch.map(FileChannel.MapMode.READ_ONLY, 0L, ch.size());
      byteArray = new byte[mb.capacity()];
      int got;
      while (mb.hasRemaining()) {
        got = Math.min(mb.remaining(), byteArray.length);
        mb.get(byteArray, 0, got);
      }
    }
  } catch (FileNotFoundException fnfe) {
    throw new IOError(fnfe);
  } catch (IOException ioe) {
    throw new IOError(ioe);
  } finally {
    if (ch != null) {
      try {
        ch.close();
        fis.close();
      } catch (IOException ioe2) {
      }
    }
  }
  return new ByteArrayInputStream(byteArray);
}
 
源代码13 项目: antsdb   文件: SpaceWarmer.java
@Override
public void run() {
    for (int i=this.sm.spaces.length-1; i>=0; i--) {
        Space ii = this.sm.spaces[i];
        if (ii != null) {
            MappedByteBuffer buf = ii.mmf.buf;
            for (int j=0; i<buf.capacity(); j+=0x100) {
                this.checksum ^= buf.get(j);
            }
        }
    }
}
 
源代码14 项目: catalyst   文件: MappedMemory.java
public MappedMemory(MappedByteBuffer buffer, MappedMemoryAllocator allocator) {
  super(((DirectBuffer) buffer).address(), buffer.capacity(), allocator);
  this.buffer = buffer;
}
 
源代码15 项目: atomix   文件: MappedMemory.java
public MappedMemory(MappedByteBuffer buffer, MappedMemoryAllocator allocator) {
  this.buffer = buffer;
  this.allocator = allocator;
  this.size = buffer.capacity();
}
 
源代码16 项目: ignite   文件: SegmentedRingByteBuffer.java
/**
 * Creates ring buffer with given capacity which mapped to file.
 *
 * @param buf {@link MappedByteBuffer} instance.
 * @param metrics Metrics.
 */
public SegmentedRingByteBuffer(MappedByteBuffer buf, DataStorageMetricsImpl metrics) {
    this(buf.capacity(), buf.capacity(), buf, MAPPED, metrics);
}