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.nettyutil.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.OutputStream;
18 import java.net.SocketAddress;
21 * Class provides {@link OutputStream) functionality to users of virtual socket.
23 public class ChannelOutputStream extends OutputStream implements ChannelOutboundHandler {
24 private final Object lock = new Object();
25 private ByteBuf buff = Unpooled.buffer();
26 private ChannelHandlerContext ctx;
31 ctx.writeAndFlush(buff).awaitUninterruptibly();
32 buff = Unpooled.buffer();
37 public void write(int b) {
43 public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
44 ChannelPromise promise) {
45 ctx.bind(localAddress, promise);
48 public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
49 SocketAddress localAddress, ChannelPromise promise) {
51 ctx.connect(remoteAddress, localAddress, promise);
54 public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) {
55 ctx.disconnect(promise);
58 public void close(ChannelHandlerContext ctx, ChannelPromise promise) {
62 public void deregister(ChannelHandlerContext ctx, ChannelPromise channelPromise) {
63 ctx.deregister(channelPromise);
66 public void read(ChannelHandlerContext ctx) {
70 public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
74 public void flush(ChannelHandlerContext ctx) {
78 public void handlerAdded(ChannelHandlerContext ctx)
82 public void handlerRemoved(ChannelHandlerContext ctx)
86 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
87 ctx.fireExceptionCaught(cause);