Mercurial > 510Connectbot
annotate src/ch/ethz/ssh2/LocalStreamForwarder.java @ 332:5c17707d94b0 ganymed
fix java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 31 Jul 2014 13:06:55 -0700 |
parents | 071eccdff8ea |
children |
rev | line source |
---|---|
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
1 /* |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
3 * Please refer to the LICENSE.txt for licensing details. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
4 */ |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
5 package ch.ethz.ssh2; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
6 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
7 import java.io.IOException; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
8 import java.io.InputStream; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
9 import java.io.OutputStream; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
10 import java.net.InetAddress; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
11 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
12 import ch.ethz.ssh2.channel.Channel; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
13 import ch.ethz.ssh2.channel.ChannelManager; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
14 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
15 /** |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
16 * A <code>LocalStreamForwarder</code> forwards an Input- and Outputstream |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
17 * pair via the secure tunnel to another host (which may or may not be identical |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
18 * to the remote SSH-2 server). |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
19 * |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
20 * @author Christian Plattner |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
21 * @version 2.50, 03/15/10 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
22 */ |
307 | 23 public class LocalStreamForwarder { |
24 private ChannelManager cm; | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
25 |
307 | 26 private Channel cn; |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
27 |
307 | 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 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
33 |
307 | 34 /** |
35 * @return An <code>InputStream</code> object. | |
36 * @throws IOException | |
37 */ | |
38 public InputStream getInputStream() throws IOException { | |
39 return cn.getStdoutStream(); | |
40 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
41 |
307 | 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 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
55 |
307 | 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 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
69 } |