KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > net > nio > TestWriteChannel


1 package org.sapia.ubik.net.nio;
2
3 import java.io.ByteArrayOutputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.nio.ByteBuffer JavaDoc;
6
7 /**
8  * @author Yanick Duchesne
9  *
10  * <dl>
11  * <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>
12  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
13  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
14  * </dl>
15  */

16 public class TestWriteChannel extends TestChannel{
17   
18   private ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
19   
20   public int write(ByteBuffer JavaDoc from){
21     byte[] toWrite = new byte[from.remaining()];
22     from.get(toWrite);
23     try{
24       out.write(toWrite);
25     }catch(IOException JavaDoc e){
26       throw new RuntimeException JavaDoc(e);
27     }
28     return toWrite.length;
29   }
30   
31   public byte[] getBytes(){
32     return out.toByteArray();
33   }
34
35 }
36
Popular Tags