...
Code Block | ||
---|---|---|
| ||
private void readIntoDirectBuffer() throws IOException { ByteBuffer buffer = ByteBuffer.allocateDirect(16*1024); FileChannel rdr = (new FileInputStream("file")).getChannel(); while(rdr.read(buffer) > 0) { // do something with the buffer buffer.clear(); } rdr.close(); } |
Note that manual clearing of the buffer data is mandatory because direct buffers are not subject to garbage collection.
Risk Assessment
Failure to limit the lifetime of sensitive data can lead to sensitive information leaks.
...