Commit d25f0f2a authored by Philip Schildkamp's avatar Philip Schildkamp

Fix large file transfer

parent b018cebc
package org.opentosca.nodetypes;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
......@@ -127,7 +128,7 @@ public class org_opentosca_nodetypes_DockerContainer_IA_Manage extends AbstractI
String whichSudo = executeCommand(container, "which sudo");
if (whichSudo == null || whichSudo.isEmpty()) {
executeCommand(container, "apt-get update && apt-get -yq install sudo");
executeCommand(container, "apt-get update && apt-get -qy install sudo");
}
}
......@@ -143,8 +144,24 @@ public class org_opentosca_nodetypes_DockerContainer_IA_Manage extends AbstractI
}
private void uploadFile(Container container, String fileContent, String targetPath) throws Exception {
String base64 = new String(Base64.getEncoder().encode(fileContent.getBytes()));
executeCommand(container, "echo '" + base64 + "' | base64 --decode > " + targetPath);
System.out.println("Uploading file to: '" + targetPath + "'");
Shell shell = new SshByPassword(container.host, container.port, container.user, container.pass);
byte[] content = fileContent.getBytes();
if (content.length < 20480) {
String base64 = new String(Base64.getEncoder().encode(content));
shell.exec("echo '" + base64 + "' | base64 --decode > " + targetPath, null, null, null);
} else {
String base64 = null;
byte[] buffer = new byte[20480];
ByteArrayInputStream stream = new ByteArrayInputStream(content);
while (stream.read(buffer) > 0) {
base64 = new String(Base64.getEncoder().encode(buffer));
shell.exec("echo '" + base64 + "' | base64 --decode >> " + targetPath, null, null, null);
buffer = new byte[stream.available() > 20480 ? 20480 : stream.available()];
}
}
}
private void waitForAvailability(Container container) throws InterruptedException, IOException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment