diff src/ch/ethz/ssh2/SCPInputStream.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/SCPInputStream.java	Wed Jul 30 13:38:04 2014 -0700
+++ b/src/ch/ethz/ssh2/SCPInputStream.java	Wed Jul 30 14:21:50 2014 -0700
@@ -12,122 +12,101 @@
 /**
  * @version $Id: SCPInputStream.java 151 2014-04-28 10:03:39Z dkocher@sudo.ch $
  */
-public class SCPInputStream extends BufferedInputStream
-{
-	private Session session;
+public class SCPInputStream extends BufferedInputStream {
+    private Session session;
 
-	/**
-	 * Bytes remaining to be read from the stream
-	 */
-	private long remaining;
+    /**
+     * Bytes remaining to be read from the stream
+     */
+    private long remaining;
 
-	public SCPInputStream(SCPClient client, Session session) throws IOException
-	{
-		super(session.getStdout());
-
-		this.session = session;
+    public SCPInputStream(SCPClient client, Session session) throws IOException {
+        super(session.getStdout());
+        this.session = session;
+        OutputStream os = new BufferedOutputStream(session.getStdin(), 512);
+        os.write(0x0);
+        os.flush();
+        final SCPClient.LenNamePair lnp;
 
-		OutputStream os = new BufferedOutputStream(session.getStdin(), 512);
+        while (true) {
+            int c = session.getStdout().read();
 
-		os.write(0x0);
-		os.flush();
-
-		final SCPClient.LenNamePair lnp;
+            if (c < 0) {
+                throw new IOException("Remote scp terminated unexpectedly.");
+            }
 
-		while (true)
-		{
-			int c = session.getStdout().read();
-			if (c < 0)
-			{
-				throw new IOException("Remote scp terminated unexpectedly.");
-			}
+            String line = client.receiveLine(session.getStdout());
 
-			String line = client.receiveLine(session.getStdout());
+            if (c == 'T') {
+                /* Ignore modification times */
+                continue;
+            }
 
-			if (c == 'T')
-			{
-				/* Ignore modification times */
-				continue;
-			}
+            if ((c == 1) || (c == 2)) {
+                throw new IOException("Remote SCP error: " + line);
+            }
 
-			if ((c == 1) || (c == 2))
-			{
-				throw new IOException("Remote SCP error: " + line);
-			}
-
-			if (c == 'C')
-			{
-				lnp = client.parseCLine(line);
-				break;
+            if (c == 'C') {
+                lnp = client.parseCLine(line);
+                break;
+            }
 
-			}
-			throw new IOException("Remote SCP error: " + ((char) c) + line);
-		}
+            throw new IOException("Remote SCP error: " + ((char) c) + line);
+        }
 
-		os.write(0x0);
-		os.flush();
-
-		this.remaining = lnp.length;
-	}
+        os.write(0x0);
+        os.flush();
+        this.remaining = lnp.length;
+    }
 
-	@Override
-	public int read() throws IOException
-	{
-		if (!(remaining > 0))
-		{
-			return -1;
-		}
+    @Override
+    public int read() throws IOException {
+        if (!(remaining > 0)) {
+            return -1;
+        }
+
+        int b = super.read();
+
+        if (b < 0) {
+            throw new IOException("Remote scp terminated connection unexpectedly");
+        }
 
-		int b = super.read();
-		if (b < 0)
-		{
-			throw new IOException("Remote scp terminated connection unexpectedly");
-		}
-
-		remaining -= 1;
+        remaining -= 1;
+        return b;
+    }
 
-		return b;
-	}
+    @Override
+    public int read(byte b[], int off, int len) throws IOException {
+        if (!(remaining > 0)) {
+            return -1;
+        }
 
-	@Override
-	public int read(byte b[], int off, int len) throws IOException
-	{
-		if (!(remaining > 0))
-		{
-			return -1;
-		}
+        int trans = (int) remaining;
 
-		int trans = (int) remaining;
-		if (remaining > len)
-		{
-			trans = len;
-		}
+        if (remaining > len) {
+            trans = len;
+        }
+
+        int read = super.read(b, off, trans);
 
-		int read = super.read(b, off, trans);
-		if (read < 0)
-		{
-			throw new IOException("Remote scp terminated connection unexpectedly");
-		}
+        if (read < 0) {
+            throw new IOException("Remote scp terminated connection unexpectedly");
+        }
 
-		remaining -= read;
-
-		return read;
-	}
+        remaining -= read;
+        return read;
+    }
 
-	@Override
-	public void close() throws IOException
-	{
-		try
-		{
-			session.getStdin().write(0x0);
-			session.getStdin().flush();
-		}
-		finally
-		{
-			if (session != null)
-			{
-				session.close();
-			}
-		}
-	}
+    @Override
+    public void close() throws IOException {
+        try {
+            session.getStdin().write(0x0);
+            session.getStdin().flush();
+        }
+        finally {
+            if (session != null) {
+                session.close();
+            }
+        }
+    }
 }