changeset 1117:0797222e066e

7901287: Utils.guessConsoleEncoding guess is wrong, yields: "UnsupportedEncodingException: cp0"
author shade
date Tue, 03 Feb 2015 12:18:35 +0300
parents 1994640176c2
children 07e7d6fb6ee1
files jmh-core/src/main/java/org/openjdk/jmh/util/UnCloseablePrintStream.java jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java
diffstat 2 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/UnCloseablePrintStream.java	Mon Feb 02 12:52:42 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/UnCloseablePrintStream.java	Tue Feb 03 12:18:35 2015 +0300
@@ -27,11 +27,12 @@
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 
 public class UnCloseablePrintStream extends PrintStream {
 
-    public UnCloseablePrintStream(OutputStream out, String charset) throws UnsupportedEncodingException {
-        super(out, false, charset);
+    public UnCloseablePrintStream(OutputStream out, Charset charset) throws UnsupportedEncodingException {
+        super(out, false, charset.name());
     }
 
     @Override
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java	Mon Feb 02 12:52:42 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java	Tue Feb 03 12:18:35 2015 +0300
@@ -34,6 +34,8 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -168,7 +170,7 @@
         return max;
     }
 
-    public static String guessConsoleEncoding() {
+    public static Charset guessConsoleEncoding() {
         // We cannot use Console class directly, because we also need the access to the raw byte stream,
         // e.g. for pushing in a raw output from a forked VM invocation. Therefore, we are left with
         // reflectively poking out the Charset from Console, and use it for our own private output streams.
@@ -180,7 +182,7 @@
             if (console != null) {
                 Object res = f.get(console);
                 if (res instanceof Charset) {
-                    return ((Charset) res).name();
+                    return (Charset) res;
                 }
             }
         } catch (NoSuchFieldException e) {
@@ -194,7 +196,7 @@
             m.setAccessible(true);
             Object res = m.invoke(null);
             if (res instanceof String) {
-                return (String) res;
+                return Charset.forName((String) res);
             }
         } catch (NoSuchMethodException e) {
             // fall-through
@@ -202,9 +204,13 @@
             // fall-through
         } catch (IllegalAccessException e) {
             // fall-through
+        } catch (IllegalCharsetNameException e) {
+            // fall-through
+        } catch (UnsupportedCharsetException e) {
+            // fall-through
         }
 
-        return Charset.defaultCharset().name();
+        return Charset.defaultCharset();
     }
 
     static class BurningTask implements Runnable {