Java Code Examples for java.nio.MappedByteBuffer#capacity()
The following examples show how to use
java.nio.MappedByteBuffer#capacity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicRoutine.java From SoftwarePilot with MIT License | 6 votes |
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]; }
Example 2
Source File: YoloVisionTest.java From SoftwarePilot with MIT License | 6 votes |
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]; }
Example 3
Source File: AutoSelfie.java From SoftwarePilot with MIT License | 6 votes |
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]; }
Example 4
Source File: WaypointMissionTest.java From SoftwarePilot with MIT License | 6 votes |
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]; }
Example 5
Source File: WaypointMissionTest.java From SoftwarePilot with MIT License | 6 votes |
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]; }
Example 6
Source File: WaypointMissionTestBackup.java From SoftwarePilot with MIT License | 6 votes |
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]; }
Example 7
Source File: RoutineTemplate.java From SoftwarePilot with MIT License | 6 votes |
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]; }
Example 8
Source File: BasicVision.java From SoftwarePilot with MIT License | 6 votes |
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]; }
Example 9
Source File: CubeSim.java From SoftwarePilot with MIT License | 6 votes |
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]; }
Example 10
Source File: VisionTest.java From SoftwarePilot with MIT License | 6 votes |
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]; }
Example 11
Source File: RdmaStorageLocalEndpoint.java From crail with Apache License 2.0 | 6 votes |
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(); } }
Example 12
Source File: FileUtil.java From cc-dbp with Apache License 2.0 | 5 votes |
/** * 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); }
Example 13
Source File: SpaceWarmer.java From antsdb with GNU Lesser General Public License v3.0 | 5 votes |
@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); } } } }
Example 14
Source File: MappedMemory.java From catalyst with Apache License 2.0 | 4 votes |
public MappedMemory(MappedByteBuffer buffer, MappedMemoryAllocator allocator) { super(((DirectBuffer) buffer).address(), buffer.capacity(), allocator); this.buffer = buffer; }
Example 15
Source File: MappedMemory.java From atomix with Apache License 2.0 | 4 votes |
public MappedMemory(MappedByteBuffer buffer, MappedMemoryAllocator allocator) { this.buffer = buffer; this.allocator = allocator; this.size = buffer.capacity(); }
Example 16
Source File: SegmentedRingByteBuffer.java From ignite with Apache License 2.0 | 2 votes |
/** * 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); }