Trying to copy a binary file(40 mb) to the target host using Add-Content command taking very long time because of the command length limit. Any suggestions if there is a way to stream.
Below is the code:
long size = Files.size(path);
final int BUFFER_SIZE = 4096; // 4KB
if(size > BUFFER_SIZE){
try (InputStream inputStream = new FileInputStream(inputFile)) {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = -1;
int offset = 0;
while ((bytesRead = inputStream.read(buffer)) != -1) {
var content = new String(Base64.getEncoder().encode(buffer));
tool.executeCommand("powershell -Command \"Add-Content '"+targetFile+"' -Value ([System.Convert]::FromBase64String('"+content+"')) -Encoding Byte\"");
}
} catch (IOException ex) {
ex.printStackTrace();
}
}