KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > net > nio > util > WriteHelper


1 package org.sapia.ubik.net.nio.util;
2
3 import java.io.IOException JavaDoc;
4 import java.nio.ByteBuffer JavaDoc;
5
6 import org.sapia.ubik.net.nio.Cycle;
7
8 /**
9  * An instance of this class writes data from the <code>ByteBuffer</code> held by the
10  * given <code>Cycle</code> and writes it to the cycle's <code>ChannelManager</code>.
11  *
12  * @see Cycle#getByteBuffer()
13  * @see Cycle#getChannel()
14  * @see Cycle#getChannelManager()
15  *
16  * @author Yanick Duchesne
17  *
18  * <dl>
19  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
20  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
21  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
22  * </dl>
23  */

24 public class WriteHelper {
25   
26   /**
27    * @param cycle a <code>Cycle</code>
28    * @throws HandlerException if a problem occurs while writing.
29    */

30   public void write(Cycle cycle) throws IOException JavaDoc{
31     ByteBuffer JavaDoc output = cycle.getByteBuffer();
32     boolean finished = false;
33     while(!finished){
34       output.clear();
35       finished = cycle.getHandler().write(cycle);
36       output.flip();
37       while(output.hasRemaining()){
38         cycle.getChannelManager().write(cycle.getChannel(), output);
39       }
40     }
41   }
42
43 }
44
Popular Tags