diff src/ch/ethz/ssh2/channel/StreamForwarder.java @ 308:42b15aaa7ac7 ganymed

merge
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:21:50 -0700
parents 071eccdff8ea
children
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/channel/StreamForwarder.java	Wed Jul 30 13:38:04 2014 -0700
+++ b/src/ch/ethz/ssh2/channel/StreamForwarder.java	Wed Jul 30 14:21:50 2014 -0700
@@ -10,106 +10,88 @@
 import java.net.Socket;
 
 /**
- * A StreamForwarder forwards data between two given streams. 
+ * A StreamForwarder forwards data between two given streams.
  * If two StreamForwarder threads are used (one for each direction)
  * then one can be configured to shutdown the underlying channel/socket
  * if both threads have finished forwarding (EOF).
- * 
+ *
  * @author Christian Plattner
  * @version 2.50, 03/15/10
  */
-public class StreamForwarder extends Thread
-{
-	OutputStream os;
-	InputStream is;
-	byte[] buffer = new byte[Channel.CHANNEL_BUFFER_SIZE];
-	Channel c;
-	StreamForwarder sibling;
-	Socket s;
-	String mode;
+public class StreamForwarder extends Thread {
+    OutputStream os;
+    InputStream is;
+    byte[] buffer = new byte[Channel.CHANNEL_BUFFER_SIZE];
+    Channel c;
+    StreamForwarder sibling;
+    Socket s;
+    String mode;
 
-	StreamForwarder(Channel c, StreamForwarder sibling, Socket s, InputStream is, OutputStream os, String mode)
-			throws IOException
-	{
-		this.is = is;
-		this.os = os;
-		this.mode = mode;
-		this.c = c;
-		this.sibling = sibling;
-		this.s = s;
-	}
+    StreamForwarder(Channel c, StreamForwarder sibling, Socket s, InputStream is, OutputStream os, String mode)
+    throws IOException {
+        this.is = is;
+        this.os = os;
+        this.mode = mode;
+        this.c = c;
+        this.sibling = sibling;
+        this.s = s;
+    }
+
+    @Override
+    public void run() {
+        try {
+            while (true) {
+                int len = is.read(buffer);
+
+                if (len <= 0)
+                    break;
 
-	@Override
-	public void run()
-	{
-		try
-		{
-			while (true)
-			{
-				int len = is.read(buffer);
-				if (len <= 0)
-					break;
-				os.write(buffer, 0, len);
-				os.flush();
-			}
-		}
-		catch (IOException e)
-		{
-			try
-			{
-				c.cm.closeChannel(c, e, true);
-			}
-			catch (IOException ignored)
-			{
-			}
-		}
-		finally
-		{
-			try
-			{
-				os.close();
-			}
-			catch (IOException ignored)
-			{
-			}
-			try
-			{
-				is.close();
-			}
-			catch (IOException ignored)
-			{
-			}
+                os.write(buffer, 0, len);
+                os.flush();
+            }
+        }
+        catch (IOException e) {
+            try {
+                c.cm.closeChannel(c, e, true);
+            }
+            catch (IOException ignored) {
+            }
+        }
+        finally {
+            try {
+                os.close();
+            }
+            catch (IOException ignored) {
+            }
+
+            try {
+                is.close();
+            }
+            catch (IOException ignored) {
+            }
 
-			if (sibling != null)
-			{
-				while (sibling.isAlive())
-				{
-					try
-					{
-						sibling.join();
-					}
-					catch (InterruptedException ignored)
-					{
-					}
-				}
+            if (sibling != null) {
+                while (sibling.isAlive()) {
+                    try {
+                        sibling.join();
+                    }
+                    catch (InterruptedException ignored) {
+                    }
+                }
 
-				try
-				{
-					c.cm.closeChannel(c, "StreamForwarder (" + mode + ") is cleaning up the connection", true);
-				}
-				catch (IOException ignored)
-				{
-				}
+                try {
+                    c.cm.closeChannel(c, "StreamForwarder (" + mode + ") is cleaning up the connection", true);
+                }
+                catch (IOException ignored) {
+                }
 
-				try
-				{
-					if (s != null)
-						s.close();
-				}
-				catch (IOException ignored)
-				{
-				}
-			}
-		}
-	}
+                try {
+                    if (s != null)
+                        s.close();
+                }
+                catch (IOException ignored) {
+                }
+            }
+        }
+    }
 }
\ No newline at end of file