1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.mina.io.handler;
20
21 import java.io.OutputStream;
22
23 import org.apache.mina.common.ByteBuffer;
24 import org.apache.mina.io.IoSession;
25
26 /***
27 * An {@link OutputStream} that forwards all write operations to
28 * the associated {@link IoSession}.
29 *
30 * @author The Apache Directory Project (dev@directory.apache.org)
31 * @version $Rev$, $Date$
32 *
33 */
34 class IoSessionOutputStream extends OutputStream
35 {
36 private final IoSession session;
37
38 IoSessionOutputStream( IoSession session )
39 {
40 this.session = session;
41 }
42
43 public void close()
44 {
45 session.close( true );
46 }
47
48 public void flush()
49 {
50 }
51
52 public void write( byte[] b, int off, int len )
53 {
54 ByteBuffer buf = ByteBuffer.wrap( b, off, len );
55 buf.acquire();
56 session.write( buf, null );
57 }
58
59 public void write( byte[] b )
60 {
61 ByteBuffer buf = ByteBuffer.wrap( b );
62 buf.acquire();
63 session.write( buf, null );
64 }
65
66 public void write( int b )
67 {
68 ByteBuffer buf = ByteBuffer.allocate( 1 );
69 buf.put( ( byte ) b );
70 buf.flip();
71 session.write( buf, null );
72 }
73 }