Skip to content

Commit 8754443

Browse files
committed
Fix stdin encoding
1 parent 39fd1f7 commit 8754443

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/main/java/com/github/dockerjava/netty/InvocationBuilder.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,8 @@
2222
import io.netty.util.concurrent.GenericFutureListener;
2323

2424
import java.io.BufferedInputStream;
25-
import java.io.BufferedReader;
2625
import java.io.IOException;
2726
import java.io.InputStream;
28-
import java.io.InputStreamReader;
29-
import java.io.UnsupportedEncodingException;
30-
import java.nio.ByteBuffer;
31-
import java.nio.charset.Charset;
3227
import java.util.HashMap;
3328
import java.util.Map;
3429

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

252-
private int read(BufferedReader reader) {
247+
private int read(InputStream is, byte[] buf) {
253248
try {
254-
return reader.read();
249+
return is.read(buf);
255250
} catch (IOException e) {
256251
throw new RuntimeException(e);
257252
}
@@ -260,19 +255,13 @@ private int read(BufferedReader reader) {
260255
@Override
261256
public void run() {
262257

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

265-
int read = -1;
266-
while ((read = read(reader)) != -1) {
267-
byte[] bytes = ByteBuffer.allocate(4).putInt(read).array();
268-
try {
269-
bytes = new String(bytes).getBytes("US-ASCII");
270-
} catch (UnsupportedEncodingException e) {
271-
throw new RuntimeException(e);
272-
}
273-
274-
channel.writeAndFlush(Unpooled.copiedBuffer(bytes));
260+
int read;
261+
while ((read = read(stdin, buffer)) != -1) {
262+
channel.writeAndFlush(Unpooled.copiedBuffer(buffer, 0, read));
275263
}
264+
276265
}
277266
}).start();
278267
}

0 commit comments

Comments
 (0)