Android Utililty Methods File to ByteBuffer Read

List of utility methods to do File to ByteBuffer Read

Description

The list of methods to do File to ByteBuffer Read are organized into topic(s).

Method

ByteBufferbufferFile(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;
ByteBufferreadToByteBuffer(File f)
read To Byte Buffer
return readToByteBuffer(f, (int) f.length());
ByteBufferreadToByteBuffer(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;