daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Aug 17th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. I/O Operation On Channels Using ByteBuffer - Performance Comparision
  2. FileChannel inChannel = new FileInputStream("input.txt").getChannel();
  3. FileChannel outChannel = new FileOutputStream("output.txt").getChannel();
  4. ByteBuffer buf = ByteBuffer.allocate(1024 * 1024);
  5.    
  6. while (inChannel.read(buf) != -1) {
  7.     buf.flip();    
  8.     while (buf.hasRemaining()) {
  9.         outChannel.write(buf);
  10.     }    
  11.     buf.clear();
  12. }
  13.    
  14. while (inChannel.read(buf) != -1 || buf.position() > 0) {
  15.     buf.flip();
  16.     outChannel.write(buf);
  17.     buf.compact();
  18. }
  19.    
  20. while (inChannel.read(buf) != -1) {
  21.     buf.flip();
  22.     outChannel.write(buf);
  23.     buf.compact();
  24. }
  25. // final flush of pending output
  26. while (buf.hasRemaining())
  27.     outChannel.write(buf);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top