diff app/src/main/java/ch/ethz/ssh2/SCPOutputStream.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/SCPOutputStream.java@071eccdff8ea
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/src/main/java/ch/ethz/ssh2/SCPOutputStream.java	Thu Dec 03 11:23:55 2015 -0800
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011 David Kocher. All rights reserved.
+ * Please refer to the LICENSE.txt for licensing details.
+ */
+package ch.ethz.ssh2;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import ch.ethz.ssh2.util.StringEncoder;
+
+/**
+ * @version $Id: SCPOutputStream.java 151 2014-04-28 10:03:39Z dkocher@sudo.ch $
+ */
+public class SCPOutputStream extends BufferedOutputStream {
+
+    private Session session;
+
+    private SCPClient scp;
+
+    public SCPOutputStream(SCPClient client, Session session, final String remoteFile, long length, String mode) throws IOException {
+        super(session.getStdin(), 40000);
+        this.session = session;
+        this.scp = client;
+        InputStream is = new BufferedInputStream(session.getStdout(), 512);
+        scp.readResponse(is);
+        String cline = "C" + mode + " " + length + " " + remoteFile + "\n";
+        super.write(StringEncoder.GetBytes(cline));
+        this.flush();
+        scp.readResponse(is);
+    }
+
+    @Override
+    public void close() throws IOException {
+        try {
+            this.write(0);
+            this.flush();
+            scp.readResponse(session.getStdout());
+            this.write(StringEncoder.GetBytes("E\n"));
+            this.flush();
+        }
+        finally {
+            if (session != null)
+                session.close();
+        }
+    }
+}