1 | /* |
2 | * @(#) $Id: AbstractIoFilterChain.java 330415 2005-11-03 02:19:03Z trustin $ |
3 | * |
4 | * Copyright 2004 The Apache Software Foundation |
5 | * |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * you may not use this file except in compliance with the License. |
8 | * You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, software |
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * See the License for the specific language governing permissions and |
16 | * limitations under the License. |
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(); // prevent from being pooled. |
56 | session.write( buf, null ); |
57 | } |
58 | |
59 | public void write( byte[] b ) |
60 | { |
61 | ByteBuffer buf = ByteBuffer.wrap( b ); |
62 | buf.acquire(); // prevent from being pooled. |
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 | } |