src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java
changeset 50552 7439ceaae8e4
parent 49001 ce06058197a4
child 50820 35f52a3cd6bd
--- a/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java	Wed Jun 13 10:36:13 2018 -0700
+++ b/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java	Wed Jun 13 12:50:45 2018 -0700
@@ -30,6 +30,7 @@
 import java.lang.reflect.Executable;
 import java.lang.reflect.Method;
 import java.net.URI;
+import java.nio.charset.Charset;
 import java.security.AccessControlContext;
 import java.security.ProtectionDomain;
 import java.util.Iterator;
@@ -256,6 +257,36 @@
     Stream<ModuleLayer> layers(ClassLoader loader);
 
     /**
+     * Constructs a new {@code String} by decoding the specified subarray of
+     * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
+     *
+     * The caller of this method shall relinquish and transfer the ownership of
+     * the byte array to the callee since the later will not make a copy.
+     *
+     * @param bytes the byte array source
+     * @param cs the Charset
+     * @return the newly created string
+     * @throws IllegalArgumentException for malformed or unmappable bytes
+     */
+    String newStringNoRepl(byte[] bytes, Charset cs);
+
+    /**
+     * Encode the given string into a sequence of bytes using the specified Charset.
+     *
+     * This method avoids copying the String's internal representation if the input
+     * is ASCII.
+     *
+     * This method throws IllegalArgumentException instead of replacing when
+     * malformed input or unmappable characters are encountered.
+     *
+     * @param s the string to encode
+     * @param cs the charset
+     * @return the encoded bytes
+     * @throws IllegalArgumentException for malformed input or unmappable characters
+     */
+    byte[] getBytesNoRepl(String s, Charset cs);
+
+    /**
      * Returns a new string by decoding from the given utf8 bytes array.
      *
      * @param off the index of the first byte to decode