2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.util.handler.ssh.virtualsocket;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import io.netty.channel.ChannelHandlerContext;
14 import io.netty.channel.ChannelOutboundHandler;
15 import io.netty.channel.ChannelPromise;
17 import java.io.IOException;
18 import java.io.OutputStream;
19 import java.net.SocketAddress;
22 * Class provides {@link OutputStream) functionality to users of virtual socket.
24 public class ChannelOutputStream extends OutputStream implements ChannelOutboundHandler {
25 private final Object lock = new Object();
26 private ByteBuf buff = Unpooled.buffer();
27 private ChannelHandlerContext ctx;
30 public void flush() throws IOException {
32 ctx.writeAndFlush(buff).awaitUninterruptibly();
33 buff = Unpooled.buffer();
38 public void write(int b) throws IOException {
44 public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
45 ChannelPromise promise) throws Exception {
46 ctx.bind(localAddress, promise);
49 public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
50 SocketAddress localAddress, ChannelPromise promise)
53 ctx.connect(remoteAddress, localAddress, promise);
56 public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise)
58 ctx.disconnect(promise);
61 public void close(ChannelHandlerContext ctx, ChannelPromise promise)
66 public void deregister(ChannelHandlerContext ctx, ChannelPromise channelPromise)
68 ctx.deregister(channelPromise);
71 public void read(ChannelHandlerContext ctx)
76 public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
81 public void flush(ChannelHandlerContext ctx)
86 public void handlerAdded(ChannelHandlerContext ctx)
90 public void handlerRemoved(ChannelHandlerContext ctx)
94 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
96 ctx.fireExceptionCaught(cause);