List of utility methods to do File to ByteBuffer Read
ByteBuffer | bufferFile(File file) buffer File long size = file.length(); ByteBuffer buf = ByteBuffer.allocate((int) (size & 0x7FFFFFFF)); FileChannel chan = new FileInputStream(file).getChannel(); while (buf.remaining() > 0) { int n = chan.read(buf); if (n <= 0) throw new IOException("Read operation failed."); chan.close(); buf.flip(); return buf; |
ByteBuffer | readToByteBuffer(File f) read To Byte Buffer return readToByteBuffer(f, (int) f.length()); |
ByteBuffer | readToByteBuffer(File f, int toRead) read To Byte Buffer ByteBuffer b = ByteBuffer.allocate(toRead); FileChannel fc = new FileInputStream(f).getChannel(); fc.read(b); fc.close(); b.flip(); return b; |