Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8274784: jshell: Garbled character was displayed by System.out.println(...) on Japanese Windows #6505

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -10,6 +10,7 @@

import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.EnumSet;
import java.util.HashMap;
@@ -55,7 +56,8 @@ public AbstractTerminal(String name, String type) throws IOException {
public AbstractTerminal(String name, String type, Charset encoding, SignalHandler signalHandler) throws IOException {
this.name = name;
this.type = type != null ? type : "ansi";
this.encoding = encoding != null ? encoding : Charset.defaultCharset();
this.encoding = encoding != null ? encoding :
Charset.forName(new OutputStreamWriter(System.out).getEncoding(), Charset.defaultCharset());
takiguc marked this conversation as resolved.
Show resolved Hide resolved
for (Signal signal : Signal.values()) {
handlers.put(signal, signalHandler);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,9 +26,11 @@

import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.net.Socket;
import java.nio.charset.Charset;

import java.util.HashMap;
import java.util.Map;
@@ -63,13 +65,19 @@ public static void main(String[] args) throws Exception {
InputStream inStream = socket.getInputStream();
OutputStream outStream = socket.getOutputStream();
Map<String, Consumer<OutputStream>> outputs = new HashMap<>();
outputs.put("out", st -> System.setOut(new PrintStream(st, true)));
outputs.put("err", st -> System.setErr(new PrintStream(st, true)));
outputs.put("out", st -> System.setOut(new PrintStream(st, true, getPrintStreamCharset(System.out))));
outputs.put("err", st -> System.setErr(new PrintStream(st, true, getPrintStreamCharset(System.err))));
Map<String, Consumer<InputStream>> input = new HashMap<>();
input.put("in", System::setIn);
forwardExecutionControlAndIO(new RemoteExecutionControl(), inStream, outStream, outputs, input);
}

// Get PrintStream charset
private static Charset getPrintStreamCharset(PrintStream ps) {
return Charset.forName(new OutputStreamWriter(ps).getEncoding(),
Charset.defaultCharset());
}

takiguc marked this conversation as resolved.
Show resolved Hide resolved
// These three variables are used by the main JShell process in interrupting
// the running process. Access is via JDI, so the reference is not visible
// to code inspection.