< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/CStringUtilities.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -23,10 +23,11 @@
  */
 
 package sun.jvm.hotspot.utilities;
 
 import java.io.*;
+import java.nio.charset.Charset;
 import java.util.*;
 
 import sun.jvm.hotspot.debugger.*;
 
 /** A utility class encapsulating useful operations on C strings

@@ -43,15 +44,19 @@
     return i;
   }
 
   private static String encoding = System.getProperty("file.encoding", "US-ASCII");
 
+  public static String getString(Address addr) {
+    return getString(addr, Charset.forName(encoding));
+  }
+
   /** Fetch a null-terminated ASCII string from the remote process.
       Returns null if the argument is null, otherwise returns a
       non-null string (for example, returns an empty string if the
       first character fetched is the null terminator). */
-  public static String getString(Address addr) {
+  public static String getString(Address addr, Charset charset) {
     if (addr == null) {
       return null;
     }
 
     List data = new ArrayList();

@@ -71,12 +76,8 @@
       bytes[(int) i] = ((Byte) data.get((int) i)).byteValue();
     }
     // FIXME: When we switch to use JDK 6 to build SA,
     // we can change the following to just return:
     // return new String(bytes, Charset.defaultCharset());
-    try {
-      return new String(bytes, encoding);
-    } catch (UnsupportedEncodingException e) {
-      throw new RuntimeException("Error converting bytes to String using " + encoding + " encoding", e);
-    }
+    return new String(bytes, charset);
   }
 }
< prev index next >