public static boolean copy ( InputStream source , ByteBuffer destination ) { try { byte [ ] buffer = new byte [ 4096 ] ; int n = 0 ; while ( - 1 != ( n = source . read ( buffer ) ) ) { destination . put ( buffer , 0 , n ) ; } return true ; } catch ( IOException e ) { return false ; } }
This method should only be used when the ByteBuffer is known to be able to accomodate the input!