Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions src/main/java/com/github/dockerjava/netty/InvocationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@
import io.netty.util.concurrent.GenericFutureListener;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -249,9 +244,9 @@ public void operationComplete(Future<? super Void> future) throws Exception {
// now we can start a new thread that reads from stdin and writes to the channel
new Thread(new Runnable() {

private int read(BufferedReader reader) {
private int read(InputStream is, byte[] buf) {
try {
return reader.read();
return is.read(buf);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -260,19 +255,13 @@ private int read(BufferedReader reader) {
@Override
public void run() {

BufferedReader reader = new BufferedReader(new InputStreamReader(stdin, Charset.forName("UTF-8")));
byte[] buffer = new byte[1024];

int read = -1;
while ((read = read(reader)) != -1) {
byte[] bytes = ByteBuffer.allocate(4).putInt(read).array();
try {
bytes = new String(bytes).getBytes("US-ASCII");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}

channel.writeAndFlush(Unpooled.copiedBuffer(bytes));
int read;
while ((read = read(stdin, buffer)) != -1) {
channel.writeAndFlush(Unpooled.copiedBuffer(buffer, 0, read));
}

}
}).start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ public void execStartAttachStdin() throws Exception {

dockerClient.startContainerCmd(container.getId()).exec();

InputStream stdin = new ByteArrayInputStream("echo STDIN\n".getBytes());
InputStream stdin = new ByteArrayInputStream("STDIN\n".getBytes("UTF-8"));

ByteArrayOutputStream stdout = new ByteArrayOutputStream();

ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withAttachStdin(true).withCmd("/bin/sh").exec();
.withAttachStdout(true).withAttachStdin(true).withCmd("cat").exec();
dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withTty(true).withStdIn(stdin)
.exec(new ExecStartResultCallback(stdout, System.err)).awaitCompletion(5, TimeUnit.SECONDS);

assertEquals(stdout.toString(), "STDIN\n");
assertEquals(stdout.toString("UTF-8"), "STDIN\n");
}

@Test(groups = "ignoreInCircleCi")
Expand Down