8272120: Avoid looking for standard encodings in "java." modules

Reviewed-by: alanb, dfuchs, naoto
This commit is contained in:
Sergey Bylokhov 2021-08-12 05:46:00 +00:00
parent bd27bb9cbe
commit ec2fc384e5
15 changed files with 74 additions and 103 deletions

View file

@ -55,6 +55,8 @@ import sun.security.x509.PKIXExtensions;
import sun.security.x509.URIName; import sun.security.x509.URIName;
import sun.security.x509.X509CertImpl; import sun.security.x509.X509CertImpl;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* This is a class that checks the revocation status of a certificate(s) using * This is a class that checks the revocation status of a certificate(s) using
* OCSP. It is not a PKIXCertPathChecker and therefore can be used outside of * OCSP. It is not a PKIXCertPathChecker and therefore can be used outside of
@ -176,7 +178,7 @@ public final class OCSP {
try { try {
String encodedGetReq = responderURI.toString() + "/" + String encodedGetReq = responderURI.toString() + "/" +
URLEncoder.encode(Base64.getEncoder().encodeToString(bytes), URLEncoder.encode(Base64.getEncoder().encodeToString(bytes),
"UTF-8"); UTF_8);
if (encodedGetReq.length() <= 255) { if (encodedGetReq.length() <= 255) {
url = new URL(encodedGetReq); url = new URL(encodedGetReq);

View file

@ -30,8 +30,6 @@ import java.io.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.channels.FileLock; import java.nio.channels.FileLock;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
@ -41,6 +39,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* HashedPasswordManager loads passwords from the password file and optionally * HashedPasswordManager loads passwords from the password file and optionally
* hashes them. * hashes them.
@ -139,7 +139,7 @@ final public class HashedPasswordManager {
MessageDigest digest = MessageDigest.getInstance(algorithm); MessageDigest digest = MessageDigest.getInstance(algorithm);
digest.reset(); digest.reset();
digest.update(salt); digest.update(salt);
byte[] hash = digest.digest(password.getBytes(StandardCharsets.UTF_8)); byte[] hash = digest.digest(password.getBytes(UTF_8));
String saltStr = Base64.getEncoder().encodeToString(salt); String saltStr = Base64.getEncoder().encodeToString(salt);
String hashStr = Base64.getEncoder().encodeToString(hash); String hashStr = Base64.getEncoder().encodeToString(hash);
@ -167,7 +167,7 @@ final public class HashedPasswordManager {
} }
lock.release(); lock.release();
} }
String str = new String(data, StandardCharsets.UTF_8); String str = new String(data, UTF_8);
return str.split("\\r?\\n"); return str.split("\\r?\\n");
} }
} }
@ -175,7 +175,7 @@ final public class HashedPasswordManager {
private void writePasswordFile(String input) throws IOException { private void writePasswordFile(String input) throws IOException {
synchronized (HashedPasswordManager.class) { synchronized (HashedPasswordManager.class) {
try (FileOutputStream fout = new FileOutputStream(passwordFile); try (FileOutputStream fout = new FileOutputStream(passwordFile);
OutputStreamWriter out = new OutputStreamWriter(fout, StandardCharsets.UTF_8); OutputStreamWriter out = new OutputStreamWriter(fout, UTF_8);
FileLock lock = fout.getChannel().lock()) { FileLock lock = fout.getChannel().lock()) {
out.write(input); out.write(input);
lock.release(); lock.release();
@ -199,7 +199,7 @@ final public class HashedPasswordManager {
MessageDigest digest = MessageDigest.getInstance(us.hashAlgorithm); MessageDigest digest = MessageDigest.getInstance(us.hashAlgorithm);
digest.reset(); digest.reset();
digest.update(salt); digest.update(salt);
ByteBuffer byteBuffer = Charset.forName("UTF-8").encode(CharBuffer.wrap(inputPassword)); ByteBuffer byteBuffer = UTF_8.encode(CharBuffer.wrap(inputPassword));
byte[] passwordBytes = new byte[byteBuffer.limit()]; byte[] passwordBytes = new byte[byteBuffer.limit()];
byteBuffer.get(passwordBytes); byteBuffer.get(passwordBytes);
byte[] hash = digest.digest(passwordBytes); byte[] hash = digest.digest(passwordBytes);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@
package javax.management.loading; package javax.management.loading;
import static com.sun.jmx.defaults.JmxProperties.MLET_LOGGER; import static com.sun.jmx.defaults.JmxProperties.MLET_LOGGER;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -164,7 +165,7 @@ class MLetParser {
conn = url.openConnection(); conn = url.openConnection();
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),
"UTF-8")); UTF_8));
// The original URL may have been redirected - this // The original URL may have been redirected - this
// sets it to whatever URL/codebase we ended up getting // sets it to whatever URL/codebase we ended up getting

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,7 +27,8 @@ package sun.management.counter.perf;
import sun.management.counter.*; import sun.management.counter.*;
import java.nio.*; import java.nio.*;
import java.io.UnsupportedEncodingException;
import static java.nio.charset.StandardCharsets.UTF_8;
class PerfDataEntry { class PerfDataEntry {
private class EntryFieldOffset { private class EntryFieldOffset {
@ -127,14 +128,7 @@ class PerfDataEntry {
} }
// convert name into a String // convert name into a String
try { name = new String(symbolBytes, UTF_8);
name = new String(symbolBytes, "UTF-8");
}
catch (UnsupportedEncodingException e) {
// should not reach here
// "UTF-8" is always a known encoding
throw new InternalError(e.getMessage(), e);
}
if (variability == Variability.INVALID) { if (variability == Variability.INVALID) {
throw new InstrumentationException("Invalid variability attribute:" + throw new InstrumentationException("Invalid variability attribute:" +

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
package sun.management.counter.perf; package sun.management.counter.perf;
import java.io.UnsupportedEncodingException; import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* A typesafe enumeration for the data types supported for * A typesafe enumeration for the data types supported for
@ -88,12 +88,7 @@ class PerfDataType {
private PerfDataType(String name, String c, int size) { private PerfDataType(String name, String c, int size) {
this.name = name; this.name = name;
this.size = size; this.size = size;
try { byte[] b = c.getBytes(UTF_8);
byte[] b = c.getBytes("UTF-8"); this.value = b[0];
this.value = b[0];
} catch (UnsupportedEncodingException e) {
// ignore, "UTF-8" is always a known encoding
throw new InternalError("Unknown encoding", e);
}
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,8 @@ import java.io.ByteArrayInputStream;
import sun.security.util.HexDumpEncoder; import sun.security.util.HexDumpEncoder;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* Base class that defines common fields, constants, and debug method. * Base class that defines common fields, constants, and debug method.
* *
@ -50,7 +52,7 @@ public abstract class Ber {
try { try {
outStream.write('\n'); outStream.write('\n');
outStream.write(tag.getBytes("UTF8")); outStream.write(tag.getBytes(UTF_8));
new HexDumpEncoder().encodeBuffer( new HexDumpEncoder().encodeBuffer(
new ByteArrayInputStream(bytes, from, to), new ByteArrayInputStream(bytes, from, to),
@ -60,7 +62,7 @@ public abstract class Ber {
} catch (IOException e) { } catch (IOException e) {
try { try {
outStream.write( outStream.write(
"Ber.dumpBER(): error encountered\n".getBytes("UTF8")); "Ber.dumpBER(): error encountered\n".getBytes(UTF_8));
} catch (IOException e2) { } catch (IOException e2) {
// ignore // ignore
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,8 @@
package com.sun.jndi.ldap; package com.sun.jndi.ldap;
import java.io.UnsupportedEncodingException; import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* A BER decoder. Contains methods to parse a BER buffer. * A BER decoder. Contains methods to parse a BER buffer.
@ -266,17 +267,9 @@ public final class BerDecoder extends Ber {
System.arraycopy(buf, offset, buf2, 0, len); System.arraycopy(buf, offset, buf2, 0, len);
if (decodeUTF8) { if (decodeUTF8) {
try { retstr = new String(buf2, UTF_8);
retstr = new String(buf2, "UTF8");
} catch (UnsupportedEncodingException e) {
throw new DecodeException("UTF8 not available on platform");
}
} else { } else {
try { retstr = new String(buf2, ISO_8859_1);
retstr = new String(buf2, "8859_1");
} catch (UnsupportedEncodingException e) {
throw new DecodeException("8859_1 not available on platform");
}
} }
offset += len; offset += len;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,8 @@
package com.sun.jndi.ldap; package com.sun.jndi.ldap;
import java.io.UnsupportedEncodingException; import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* A BER encoder. * A BER encoder.
@ -316,19 +317,11 @@ public final class BerEncoder extends Ber {
if (str == null) { if (str == null) {
count = 0; count = 0;
} else if (encodeUTF8) { } else if (encodeUTF8) {
try { bytes = str.getBytes(UTF_8);
bytes = str.getBytes("UTF8"); count = bytes.length;
count = bytes.length;
} catch (UnsupportedEncodingException e) {
throw new EncodeException("UTF8 not available on platform");
}
} else { } else {
try { bytes = str.getBytes(ISO_8859_1);
bytes = str.getBytes("8859_1"); count = bytes.length;
count = bytes.length;
} catch (UnsupportedEncodingException e) {
throw new EncodeException("8859_1 not available on platform");
}
} }
encodeLength(count); encodeLength(count);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,6 +30,9 @@ import javax.naming.directory.InvalidSearchFilterException;
import java.io.IOException; import java.io.IOException;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* LDAP (RFC-1960) and LDAPv3 (RFC-2254) search filters. * LDAP (RFC-1960) and LDAPv3 (RFC-2254) search filters.
* *
@ -59,9 +62,9 @@ final class Filter {
byte[] filter; byte[] filter;
int filterLen; int filterLen;
if (isLdapv3) { if (isLdapv3) {
filter = filterStr.getBytes("UTF8"); filter = filterStr.getBytes(UTF_8);
} else { } else {
filter = filterStr.getBytes("8859_1"); filter = filterStr.getBytes(ISO_8859_1);
} }
filterLen = filter.length; filterLen = filter.length;
if (dbg) { if (dbg) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -39,6 +39,9 @@ import com.sun.jndi.ldap.pool.PoolCallback;
import com.sun.jndi.ldap.sasl.LdapSasl; import com.sun.jndi.ldap.sasl.LdapSasl;
import com.sun.jndi.ldap.sasl.SaslInputStream; import com.sun.jndi.ldap.sasl.SaslInputStream;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* LDAP (RFC-1777) and LDAPv3 (RFC-2251) compliant client * LDAP (RFC-1777) and LDAPv3 (RFC-2251) compliant client
* *
@ -421,9 +424,9 @@ public final class LdapClient implements PooledConnection {
if (pw instanceof String) { if (pw instanceof String) {
if (v3) { if (v3) {
return ((String)pw).getBytes("UTF8"); return ((String)pw).getBytes(UTF_8);
} else { } else {
return ((String)pw).getBytes("8859_1"); return ((String)pw).getBytes(ISO_8859_1);
} }
} else { } else {
return (byte[])pw; return (byte[])pw;
@ -1153,7 +1156,7 @@ public final class LdapClient implements PooledConnection {
// replace any escaped characters in the value // replace any escaped characters in the value
byte[] val = isLdapv3 ? byte[] val = isLdapv3 ?
value.getBytes("UTF8") : value.getBytes("8859_1"); value.getBytes(UTF_8) : value.getBytes(ISO_8859_1);
ber.encodeOctetString( ber.encodeOctetString(
Filter.unescapeFilterValue(val, 0, val.length), Filter.unescapeFilterValue(val, 0, val.length),
Ber.ASN_OCTET_STR); Ber.ASN_OCTET_STR);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -35,6 +35,7 @@ import javax.naming.directory.Attributes;
import javax.naming.directory.Attribute; import javax.naming.directory.Attribute;
import javax.naming.directory.BasicAttributes; import javax.naming.directory.BasicAttributes;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* <code>LdapName</code> implements compound names for LDAP v3 as * <code>LdapName</code> implements compound names for LDAP v3 as
@ -900,11 +901,7 @@ public final class LdapName implements Name {
// Convert hex-encoded UTF-8 to 16-bit chars. // Convert hex-encoded UTF-8 to 16-bit chars.
byte[] utf8 = getUtf8Octets(chars, i, end); byte[] utf8 = getUtf8Octets(chars, i, end);
if (utf8.length > 0) { if (utf8.length > 0) {
try { buf.append(new String(utf8, UTF_8));
buf.append(new String(utf8, "UTF8"));
} catch (java.io.UnsupportedEncodingException e) {
// shouldn't happen
}
i += utf8.length * 3 - 1; i += utf8.length * 3 - 1;
} else { } else {
throw new IllegalArgumentException( throw new IllegalArgumentException(

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,6 +30,8 @@ import javax.security.sasl.RealmCallback;
import javax.security.sasl.RealmChoiceCallback; import javax.security.sasl.RealmChoiceCallback;
import java.io.IOException; import java.io.IOException;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* DefaultCallbackHandler for satisfying NameCallback and * DefaultCallbackHandler for satisfying NameCallback and
* PasswordCallback for an LDAP client. * PasswordCallback for an LDAP client.
@ -60,7 +62,7 @@ final class DefaultCallbackHandler implements CallbackHandler {
passwd = ((char[])cred).clone(); passwd = ((char[])cred).clone();
} else if (cred != null) { } else if (cred != null) {
// assume UTF-8 encoding // assume UTF-8 encoding
String orig = new String((byte[])cred, "UTF8"); String orig = new String((byte[])cred, UTF_8);
passwd = orig.toCharArray(); passwd = orig.toCharArray();
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -43,6 +43,8 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.IOException; import java.io.IOException;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* This class represents a relative distinguished name, or RDN, which is a * This class represents a relative distinguished name, or RDN, which is a
* component of a distinguished name as specified by * component of a distinguished name as specified by
@ -643,11 +645,7 @@ public class Rdn implements Serializable, Comparable<Object> {
// Convert hex-encoded UTF-8 to 16-bit chars. // Convert hex-encoded UTF-8 to 16-bit chars.
byte[] utf8 = getUtf8Octets(chars, i, end); byte[] utf8 = getUtf8Octets(chars, i, end);
if (utf8.length > 0) { if (utf8.length > 0) {
try { builder.append(new String(utf8, UTF_8));
builder.append(new String(utf8, "UTF8"));
} catch (java.io.UnsupportedEncodingException e) {
// shouldn't happen
}
i += utf8.length * 3 - 1; i += utf8.length * 3 - 1;
} else { // no utf8 bytes available, invalid DN } else { // no utf8 bytes available, invalid DN

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -36,6 +36,7 @@ import java.net.http.HttpResponse;
import jdk.internal.net.http.common.Logger; import jdk.internal.net.http.common.Logger;
import jdk.internal.net.http.common.Utils; import jdk.internal.net.http.common.Utils;
import static java.lang.String.format; import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* Implements chunked/fixed transfer encodings of HTTP/1.1 responses. * Implements chunked/fixed transfer encodings of HTTP/1.1 responses.
@ -159,7 +160,7 @@ class ResponseContent {
printable.get(bytes, 0, bytes.length); printable.get(bytes, 0, bytes.length);
String msg = "============== accepted ==================\n"; String msg = "============== accepted ==================\n";
try { try {
var str = new String(bytes, "UTF-8"); var str = new String(bytes, UTF_8);
msg += str; msg += str;
} catch (Exception x) { } catch (Exception x) {
msg += x; msg += x;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,10 +24,11 @@
*/ */
package javax.xml.catalog; package javax.xml.catalog;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* The Normalizer is responsible for normalizing Public and System Identifiers * The Normalizer is responsible for normalizing Public and System Identifiers
* as specified in section 6.2, 6.3 and 6.4 of the specification * as specified in section 6.2, 6.3 and 6.4 of the specification
@ -93,13 +94,9 @@ class Normalizer {
static String encodeURN(String publicId) { static String encodeURN(String publicId) {
String urn = normalizePublicId(publicId); String urn = normalizePublicId(publicId);
try { urn = URLEncoder.encode(urn, UTF_8);
urn = URLEncoder.encode(urn, "UTF-8"); urn = urn.replace("::", ";");
urn = urn.replace("::", ";"); urn = urn.replace("//", ":");
urn = urn.replace("//", ":");
} catch (UnsupportedEncodingException ex) {
CatalogMessages.reportRunTimeError(CatalogMessages.ERR_OTHER, ex);
}
return Util.URN + urn; return Util.URN + urn;
} }
@ -119,13 +116,9 @@ class Normalizer {
} else { } else {
return urn; return urn;
} }
try { publicId = publicId.replace(":", "//");
publicId = publicId.replace(":", "//"); publicId = publicId.replace(";", "::");
publicId = publicId.replace(";", "::"); publicId = URLDecoder.decode(publicId, UTF_8);
publicId = URLDecoder.decode(publicId, "UTF-8");
} catch (UnsupportedEncodingException ex) {
CatalogMessages.reportRunTimeError(CatalogMessages.ERR_OTHER, ex);
}
return publicId; return publicId;
} }
@ -141,14 +134,8 @@ class Normalizer {
return null; return null;
} }
byte[] bytes;
uriref = uriref.trim(); uriref = uriref.trim();
try { byte[] bytes = uriref.getBytes(UTF_8);
bytes = uriref.getBytes("UTF-8");
} catch (UnsupportedEncodingException uee) {
// this can't happen
return uriref;
}
StringBuilder newRef = new StringBuilder(bytes.length); StringBuilder newRef = new StringBuilder(bytes.length);
for (int count = 0; count < bytes.length; count++) { for (int count = 0; count < bytes.length; count++) {