1 package org.jgroups.util; 2 3 import java.io.IOException ; 4 import java.nio.ByteBuffer ; 5 import java.nio.channels.WritableByteChannel ; 6 7 12 public class Util1_4 extends Util 13 { 14 15 16 public static void doubleWriteBuffer( 17 ByteBuffer buf, 18 WritableByteChannel out) 19 throws Exception ![JavaDoc](../../../../cmn/javadoc.gif) 20 { 21 if (buf.limit() > 1) 22 { 23 int actualLimit = buf.limit(); 24 buf.limit(1); 25 writeFully(buf,out); 26 buf.limit(actualLimit); 27 writeFully(buf,out); 28 } 29 else 30 { 31 buf.limit(0); 32 writeFully(buf,out); 33 buf.limit(1); 34 writeFully(buf,out); 35 } 36 } 37 38 45 public static void writeFully(ByteBuffer buf, WritableByteChannel out) 46 throws IOException ![JavaDoc](../../../../cmn/javadoc.gif) 47 { 48 int written = 0; 49 int toWrite = buf.limit(); 50 while (written < toWrite) 51 { 52 written += out.write(buf); 53 } 54 } 55 } 56 | Popular Tags |