Skip to content

Commit

Permalink
Using Google's Files class to read a file to bytes[].
Browse files Browse the repository at this point in the history
  • Loading branch information
klauern committed Sep 3, 2010
1 parent 7235a8b commit 7b92d72
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/main/java/klauer/ssh/interactive/RunningAScript.java
@@ -1,5 +1,6 @@
package klauer.ssh.interactive;

import com.google.common.io.Files;
import java.io.IOException;
import java.io.InputStream;

Expand Down Expand Up @@ -29,21 +30,10 @@ public static void main(String[] args) throws IOException {
session.connect();
ChannelExec channel = (ChannelExec) session.openChannel(ChannelTypes.EXEC.toString());


InputStream in = channel.getInputStream();

File scriptfile = new File(nui.script_to_load);
FileInputStream fis = new FileInputStream(scriptfile);

byte[] commandbytes = new byte[(int) scriptfile.length()];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < commandbytes.length && (numRead = fis.read(commandbytes, offset, commandbytes.length - offset)) >= 0) {
offset += numRead;
}

channel.setCommand(commandbytes);
channel.setCommand(Files.toByteArray(new File(nui.script_to_load)));
channel.setErrStream(System.out);

channel.connect();
Expand Down

0 comments on commit 7b92d72

Please sign in to comment.