comparison app/src/main/java/ch/ethz/ssh2/LocalStreamForwarder.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/ch/ethz/ssh2/LocalStreamForwarder.java@071eccdff8ea
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
1 /*
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 * Please refer to the LICENSE.txt for licensing details.
4 */
5 package ch.ethz.ssh2;
6
7 import java.io.IOException;
8 import java.io.InputStream;
9 import java.io.OutputStream;
10 import java.net.InetAddress;
11
12 import ch.ethz.ssh2.channel.Channel;
13 import ch.ethz.ssh2.channel.ChannelManager;
14
15 /**
16 * A <code>LocalStreamForwarder</code> forwards an Input- and Outputstream
17 * pair via the secure tunnel to another host (which may or may not be identical
18 * to the remote SSH-2 server).
19 *
20 * @author Christian Plattner
21 * @version 2.50, 03/15/10
22 */
23 public class LocalStreamForwarder {
24 private ChannelManager cm;
25
26 private Channel cn;
27
28 LocalStreamForwarder(ChannelManager cm, String host_to_connect, int port_to_connect) throws IOException {
29 this.cm = cm;
30 cn = cm.openDirectTCPIPChannel(host_to_connect, port_to_connect,
31 InetAddress.getLocalHost().getHostAddress(), 0);
32 }
33
34 /**
35 * @return An <code>InputStream</code> object.
36 * @throws IOException
37 */
38 public InputStream getInputStream() throws IOException {
39 return cn.getStdoutStream();
40 }
41
42 /**
43 * Get the OutputStream. Please be aware that the implementation MAY use an
44 * internal buffer. To make sure that the buffered data is sent over the
45 * tunnel, you have to call the <code>flush</code> method of the
46 * <code>OutputStream</code>. To signal EOF, please use the
47 * <code>close</code> method of the <code>OutputStream</code>.
48 *
49 * @return An <code>OutputStream</code> object.
50 * @throws IOException
51 */
52 public OutputStream getOutputStream() throws IOException {
53 return cn.getStdinStream();
54 }
55
56 /**
57 * Close the underlying SSH forwarding channel and free up resources.
58 * You can also use this method to force the shutdown of the underlying
59 * forwarding channel. Pending output (OutputStream not flushed) will NOT
60 * be sent. Pending input (InputStream) can still be read. If the shutdown
61 * operation is already in progress (initiated from either side), then this
62 * call is a no-op.
63 *
64 * @throws IOException
65 */
66 public void close() throws IOException {
67 cm.closeChannel(cn, "Closed due to user request.", true);
68 }
69 }