public static ByteBuffer toByteBuffer ( File file ) { ByteBuffer buffer = ByteBuffer . allocateDirect ( ( int ) file . length ( ) ) ; try { buffer . put ( toByteArray ( new FileInputStream ( file ) ) ) ; } catch ( IOException e ) { logger . error ( "Failed to write file to byte array: " + e . getMessage ( ) ) ; } buffer . flip ( ) ; return buffer ; }
Convert a File into a ByteBuffer