src/share/classes/java/util/zip/ZipCoder.java

Print this page
rev 3975 : 4884238: Adds java.nio.charset.StandardCharset to provide static final constants for the standard charsets.

@@ -26,10 +26,11 @@
 package java.util.zip;
 
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.CoderResult;
 import java.nio.charset.CodingErrorAction;
 import java.util.Arrays;

@@ -85,20 +86,20 @@
     // assume invoked only if "this" is not utf8
     byte[] getBytesUTF8(String s) {
         if (isutf8)
             return getBytes(s);
         if (utf8 == null)
-            utf8 = new ZipCoder(Charset.forName("UTF-8"));
+            utf8 = new ZipCoder(StandardCharset.UTF_8);
         return utf8.getBytes(s);
     }
 
 
     String toStringUTF8(byte[] ba, int len) {
         if (isutf8)
             return toString(ba, len);
         if (utf8 == null)
-            utf8 = new ZipCoder(Charset.forName("UTF-8"));
+            utf8 = new ZipCoder(StandardCharset.UTF_8);
         return utf8.toString(ba, len);
     }
 
     boolean isUTF8() {
         return isutf8;

@@ -110,11 +111,11 @@
     private boolean isutf8;
     private ZipCoder utf8;
 
     private ZipCoder(Charset cs) {
         this.cs = cs;
-        this.isutf8 = cs.name().equals("UTF-8");
+        this.isutf8 = cs.name().equals(StandardCharset.UTF_8.name());
     }
 
     static ZipCoder get(Charset charset) {
         return new ZipCoder(charset);
     }