Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java (working copy) @@ -21,6 +21,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import java.security.AccessControlContext; import java.security.AccessController; import java.util.ArrayList; @@ -587,7 +588,7 @@ uuidFile.makeParentDirs(); OutputStream out = uuidFile.getOutputStream(); try { - out.write(ROOT_NODE_ID.toString().getBytes("US-ASCII")); + out.write(ROOT_NODE_ID.toString().getBytes(StandardCharsets.US_ASCII)); return ROOT_NODE_ID; } finally { IOUtils.closeQuietly(out); Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java (working copy) @@ -22,6 +22,8 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collection; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import javax.jcr.Node; import javax.jcr.PathNotFoundException; @@ -46,7 +48,7 @@ /** * The encoding of the test resources. */ - private static final String ENCODING = "UTF-8"; + private static final Charset ENCODING = StandardCharsets.UTF_8; public void loadTestContent(Session session) throws RepositoryException, IOException { JackrabbitWorkspace workspace = @@ -151,7 +153,7 @@ Node resource = node.addNode("myResource", "nt:resource"); // nt:resource not longer referenceable since JCR 2.0 resource.addMixin("mix:referenceable"); - resource.setProperty("jcr:encoding", ENCODING); + resource.setProperty("jcr:encoding", ENCODING.name()); resource.setProperty("jcr:mimeType", "text/plain"); resource.setProperty( "jcr:data", @@ -173,7 +175,7 @@ // NodeDefTest requires a test node with a mandatory child node JcrUtils.putFile( node, "testFile", "text/plain", - new ByteArrayInputStream("Hello, World!".getBytes("UTF-8"))); + new ByteArrayInputStream("Hello, World!".getBytes(StandardCharsets.UTF_8))); } /** @@ -243,7 +245,7 @@ getOrAddNode(node, prefix + "MultiNoBin").setProperty(name, texts); Node resource = getOrAddNode(node, prefix + "MultiBin"); - resource.setProperty("jcr:encoding", ENCODING); + resource.setProperty("jcr:encoding", ENCODING.name()); resource.setProperty("jcr:mimeType", "text/plain"); String[] values = new String[] { "SGVsbG8gd8O2cmxkLg==", "SGVsbG8gd8O2cmxkLg==" }; @@ -253,7 +255,7 @@ getOrAddNode(node, prefix + "NoBin").setProperty(name, "text 1"); resource = getOrAddNode(node, "invalidBin"); - resource.setProperty("jcr:encoding", ENCODING); + resource.setProperty("jcr:encoding", ENCODING.name()); resource.setProperty("jcr:mimeType", "text/plain"); byte[] bytes = "Hello w\u00F6rld.".getBytes(ENCODING); resource.setProperty(name, new ByteArrayInputStream(bytes)); Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java (working copy) @@ -21,6 +21,7 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -790,7 +791,7 @@ try { in = getClass().getClassLoader().getResourceAsStream(BUILTIN_NODETYPES_RESOURCE_PATH); if (in != null) { - Reader r = new InputStreamReader(in, "utf-8"); + Reader r = new InputStreamReader(in, StandardCharsets.UTF_8); store.loadCND(r, BUILTIN_NODETYPES_RESOURCE_PATH); } } catch (IOException ioe) { Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java (working copy) @@ -17,6 +17,7 @@ package org.apache.jackrabbit.core.nodetype.virtual; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Collection; @@ -251,12 +252,10 @@ private static NodeId calculateStableId(String name) throws RepositoryException { try { MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] digest = md.digest(name.getBytes("utf-8")); + byte[] digest = md.digest(name.getBytes(StandardCharsets.UTF_8)); return new NodeId(digest); } catch (NoSuchAlgorithmException e) { throw new RepositoryException(e); - } catch (UnsupportedEncodingException e) { - throw new RepositoryException(e); } } Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleDumper.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleDumper.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleDumper.java (working copy) @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; @@ -368,7 +369,7 @@ int len = in.readInt(); byte[] bytes = new byte[len]; in.readFully(bytes); - buffer.append(" value: string: ").append(new String(bytes, "UTF-8")).append("\n"); + buffer.append(" value: string: ").append(new String(bytes, StandardCharsets.UTF_8)).append("\n"); } } } @@ -463,7 +464,7 @@ namespaces[ns] = uri; } } - String local = new String(readBytes((b & 0x0f) + 1, 0x10), "UTF-8"); + String local = new String(readBytes((b & 0x0f) + 1, 0x10), StandardCharsets.UTF_8); return uri + ":" + local; } } @@ -603,7 +604,7 @@ private String readString() throws IOException { if (version >= VERSION_3) { - return new String(readBytes(0, 0), "UTF-8"); + return new String(readBytes(0, 0), StandardCharsets.UTF_8); } else { return in.readUTF(); } Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java (working copy) @@ -30,6 +30,7 @@ import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.Calendar; import java.util.Collections; import java.util.GregorianCalendar; @@ -410,7 +411,7 @@ int len = in.readInt(); byte[] bytes = new byte[len]; in.readFully(bytes); - String stringVal = new String(bytes, "UTF-8"); + String stringVal = new String(bytes, StandardCharsets.UTF_8); // https://issues.apache.org/jira/browse/JCR-3083 if (PropertyType.DATE == entry.getType()) { @@ -518,7 +519,7 @@ } } - String local = new String(readBytes((b & 0x0f) + 1, 0x10), "UTF-8"); + String local = new String(readBytes((b & 0x0f) + 1, 0x10), StandardCharsets.UTF_8); return NameFactoryImpl.getInstance().create(uri, local); } @@ -659,7 +660,7 @@ private String readString() throws IOException { if (version >= BundleBinding.VERSION_3) { - return new String(readBytes(0, 0), "UTF-8"); + return new String(readBytes(0, 0), StandardCharsets.UTF_8); } else { return in.readUTF(); } Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java (working copy) @@ -22,6 +22,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.Calendar; import java.util.Collection; import java.util.GregorianCalendar; @@ -464,7 +465,7 @@ if (local.length() == 0) { throw new IOException("Attempt to write an empty local name: " + name); } - byte[] bytes = local.getBytes("UTF-8"); + byte[] bytes = local.getBytes(StandardCharsets.UTF_8); int len = Math.min(bytes.length - 1, 0x0f); out.writeByte(0x80 | ns << 4 | len); @@ -707,7 +708,7 @@ * @throws IOException if an I/O error occurs */ private void writeString(String value) throws IOException { - writeBytes(value.getBytes("UTF-8"), 0); + writeBytes(value.getBytes(StandardCharsets.UTF_8), 0); } /** Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java (working copy) @@ -34,6 +34,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -55,7 +57,7 @@ /** * encoding used for serializing String values */ - private static final String ENCODING = "UTF-8"; + private static final Charset ENCODING = StandardCharsets.UTF_8; /** * Serializes the specified NodeState object to the given Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java (working copy) @@ -53,6 +53,8 @@ import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; @@ -80,7 +82,7 @@ /** * The default encoding used in serialization */ - public static final String DEFAULT_ENCODING = "UTF-8"; + public static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8; /** * The XML elements and attributes used in serialization @@ -544,19 +546,11 @@ OutputStream os = nodeFile.getOutputStream(); Writer writer = null; try { - String encoding = DEFAULT_ENCODING; - try { - writer = new BufferedWriter(new OutputStreamWriter(os, encoding)); - } catch (UnsupportedEncodingException e) { - // should never get here! - OutputStreamWriter osw = new OutputStreamWriter(os); - encoding = osw.getEncoding(); - writer = new BufferedWriter(osw); - } + writer = new BufferedWriter(new OutputStreamWriter(os, DEFAULT_ENCODING)); String parentId = (state.getParentId() == null) ? "" : state.getParentId().toString(); String encodedNodeType = Text.encodeIllegalXMLCharacters(state.getNodeTypeName().toString()); - writer.write("\n"); + writer.write("\n"); writer.write("<" + NODE_ELEMENT + " " + UUID_ATTRIBUTE + "=\"" + id + "\" " + PARENTUUID_ATTRIBUTE + "=\"" + parentId + "\" " @@ -618,15 +612,7 @@ // write property state to xml file Writer writer = null; try { - String encoding = DEFAULT_ENCODING; - try { - writer = new BufferedWriter(new OutputStreamWriter(os, encoding)); - } catch (UnsupportedEncodingException e) { - // should never get here! - OutputStreamWriter osw = new OutputStreamWriter(os); - encoding = osw.getEncoding(); - writer = new BufferedWriter(osw); - } + writer = new BufferedWriter(new OutputStreamWriter(os, DEFAULT_ENCODING)); String typeName; int type = state.getType(); @@ -637,7 +623,7 @@ throw new ItemStateException("unexpected property-type ordinal: " + type, iae); } - writer.write("\n"); + writer.write("\n"); writer.write("<" + PROPERTY_ELEMENT + " " + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(state.getName().toString()) + "\" " + PARENTUUID_ATTRIBUTE + "=\"" + state.getParentId() + "\" " @@ -815,16 +801,9 @@ OutputStream os = refsFile.getOutputStream(); BufferedWriter writer = null; try { - String encoding = DEFAULT_ENCODING; - try { - writer = new BufferedWriter(new OutputStreamWriter(os, encoding)); - } catch (UnsupportedEncodingException e) { - // should never get here! - OutputStreamWriter osw = new OutputStreamWriter(os); - encoding = osw.getEncoding(); - writer = new BufferedWriter(osw); - } - writer.write("\n"); + writer = new BufferedWriter(new OutputStreamWriter(os, DEFAULT_ENCODING)); + + writer.write("\n"); writer.write("<" + NODEREFERENCES_ELEMENT + " " + TARGETID_ATTRIBUTE + "=\"" + refs.getTargetId() + "\">\n"); // write references (i.e. the id's of the REFERENCE properties) Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueStore.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueStore.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueStore.java (working copy) @@ -25,6 +25,8 @@ import java.io.InputStream; import java.io.BufferedReader; import java.io.InputStreamReader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Set; import java.util.HashSet; @@ -45,7 +47,7 @@ /** * Encoding of the indexing queue store. */ - private static final String ENCODING = "UTF-8"; + private static final Charset ENCODING = StandardCharsets.UTF_8; /** * Operation identifier for an added node. Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/token/TokenProvider.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/token/TokenProvider.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/token/TokenProvider.java (working copy) @@ -175,9 +175,6 @@ } catch (NoSuchAlgorithmException e) { // error while generating login token log.error(error, e); - } catch (UnsupportedEncodingException e) { - // error while generating login token - log.error(error, e); } catch (AccessDeniedException e) { log.warn(error, e); } Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/PasswordUtility.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/PasswordUtility.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/PasswordUtility.java (working copy) @@ -17,7 +17,8 @@ package org.apache.jackrabbit.core.security.user; -import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; @@ -35,7 +36,7 @@ private static final char DELIMITER = '-'; private static final int NO_ITERATIONS = 1; - private static final String ENCODING = "UTF-8"; + private static final Charset ENCODING = StandardCharsets.UTF_8; public static final String DEFAULT_ALGORITHM = "SHA-256"; public static final int DEFAULT_SALT_SIZE = 8; @@ -53,9 +54,8 @@ * @param password The password to be hashed. * @return The password hash. * @throws NoSuchAlgorithmException If {@link #DEFAULT_ALGORITHM} is not supported. - * @throws UnsupportedEncodingException If utf-8 is not supported. */ - public static String buildPasswordHash(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException { + public static String buildPasswordHash(String password) throws NoSuchAlgorithmException { return buildPasswordHash(password, DEFAULT_ALGORITHM, DEFAULT_SALT_SIZE, DEFAULT_ITERATIONS); } @@ -71,10 +71,9 @@ * integer is lower than 1 the {@link #DEFAULT_ITERATIONS default} value is used. * @return The password hash. * @throws NoSuchAlgorithmException If the specified algorithm is not supported. - * @throws UnsupportedEncodingException If utf-8 is not supported. */ public static String buildPasswordHash(String password, String algorithm, - int saltSize, int iterations) throws NoSuchAlgorithmException, UnsupportedEncodingException { + int saltSize, int iterations) throws NoSuchAlgorithmException { if (password == null) { throw new IllegalArgumentException("Password may not be null."); } @@ -127,8 +126,6 @@ } // hashedPassword is plaintext -> return false } catch (NoSuchAlgorithmException e) { log.warn(e.getMessage()); - } catch (UnsupportedEncodingException e) { - log.warn(e.getMessage()); } return false; } @@ -164,7 +161,7 @@ //------------------------------------------------------------< private >--- - private static String generateHash(String pwd, String algorithm, String salt, int iterations) throws NoSuchAlgorithmException, UnsupportedEncodingException { + private static String generateHash(String pwd, String algorithm, String salt, int iterations) throws NoSuchAlgorithmException { StringBuilder passwordHash = new StringBuilder(); passwordHash.append('{').append(algorithm).append('}'); if (salt != null && salt.length() > 0) { @@ -196,7 +193,7 @@ return res.toString(); } - private static String generateDigest(String data, String algorithm, int iterations) throws UnsupportedEncodingException, NoSuchAlgorithmException { + private static String generateDigest(String data, String algorithm, int iterations) throws NoSuchAlgorithmException { byte[] bytes = data.getBytes(ENCODING); MessageDigest md = MessageDigest.getInstance(algorithm); Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java (working copy) @@ -52,6 +52,7 @@ import javax.jcr.nodetype.ConstraintViolationException; import javax.jcr.version.VersionException; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.security.Principal; import java.util.HashSet; @@ -773,8 +774,6 @@ pwHash = PasswordUtility.buildPasswordHash(password, algorithm, PasswordUtility.DEFAULT_SALT_SIZE, iterations); } catch (NoSuchAlgorithmException e) { throw new RepositoryException(e); - } catch (UnsupportedEncodingException e) { - throw new RepositoryException(e); } } else { pwHash = password; @@ -1052,15 +1051,10 @@ * * @param id The user/group id that needs to be converted to a valid NodeId. * @return a new NodeId. - * @throws RepositoryException If an error occurs. */ - private NodeId buildNodeId(String id) throws RepositoryException { - try { - UUID uuid = UUID.nameUUIDFromBytes(id.toLowerCase().getBytes("UTF-8")); - return new NodeId(uuid); - } catch (UnsupportedEncodingException e) { - throw new RepositoryException("Unexpected error while build ID hash", e); - } + private NodeId buildNodeId(String id) { + UUID uuid = UUID.nameUUIDFromBytes(id.toLowerCase().getBytes(StandardCharsets.UTF_8)); + return new NodeId(uuid); } /** Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java (revision 1819267) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java (working copy) @@ -45,6 +45,7 @@ import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; /** * BufferedStringValue represents an appendable @@ -122,7 +123,7 @@ if (base64) { ByteArrayOutputStream out = new ByteArrayOutputStream(); Base64.decode(value, out); - value = new String(out.toByteArray(), "UTF-8"); + value = new String(out.toByteArray(), StandardCharsets.UTF_8); } return value; } @@ -161,7 +162,7 @@ private Reader openReader() throws IOException { return new InputStreamReader( - new BufferedInputStream(new FileInputStream(tmpFile)), "UTF-8"); + new BufferedInputStream(new FileInputStream(tmpFile)), StandardCharsets.UTF_8); } /** @@ -199,7 +200,7 @@ TransientFileFactory fileFactory = TransientFileFactory.getInstance(); tmpFile = fileFactory.createTransientFile("txt", null, null); BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(tmpFile)); - writer = new OutputStreamWriter(fout, "UTF-8"); + writer = new OutputStreamWriter(fout, StandardCharsets.UTF_8); writer.write(buffer.toString()); writer.write(chars, start, len); // reset the in-memory buffer Index: jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/AbstractUserTest.java =================================================================== --- jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/AbstractUserTest.java (revision 1819267) +++ jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/AbstractUserTest.java (working copy) @@ -31,6 +31,7 @@ import javax.jcr.UnsupportedRepositoryOperationException; import javax.security.auth.Subject; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.security.Principal; import java.util.Collections; @@ -103,12 +104,10 @@ try { StringBuilder password = new StringBuilder(); password.append("{").append(SecurityConstants.DEFAULT_DIGEST).append("}"); - password.append(Text.digest(SecurityConstants.DEFAULT_DIGEST, uid.getBytes("UTF-8"))); + password.append(Text.digest(SecurityConstants.DEFAULT_DIGEST, uid.getBytes(StandardCharsets.UTF_8))); return password.toString(); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e.toString()); - } catch (UnsupportedEncodingException e) { - throw new IllegalArgumentException(e.toString()); } } else { return uid; Index: jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java =================================================================== --- jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java (revision 1819267) +++ jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java (working copy) @@ -16,6 +16,7 @@ */ package org.apache.jackrabbit.core.data; +import java.nio.charset.StandardCharsets; import java.security.SecureRandom; import javax.crypto.Mac; @@ -98,7 +99,7 @@ Mac mac = Mac.getInstance(ALGORITHM); mac.init(new SecretKeySpec(getReferenceKey(), ALGORITHM)); - byte[] hash = mac.doFinal(id.getBytes("UTF-8")); + byte[] hash = mac.doFinal(id.getBytes(StandardCharsets.UTF_8)); return id + ':' + encodeHexString(hash); } catch (Exception e) { Index: jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataStore.java =================================================================== --- jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataStore.java (revision 1819267) +++ jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataStore.java (working copy) @@ -24,6 +24,7 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; +import java.nio.charset.StandardCharsets; import java.security.DigestOutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -681,11 +682,7 @@ @Override protected byte[] getOrCreateReferenceKey() throws DataStoreException { - try { - return secret.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new DataStoreException(e); - } + return secret.getBytes(StandardCharsets.UTF_8); } public Set getPendingUploads() { Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/ToXmlContentHandler.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/ToXmlContentHandler.java (revision 1819267) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/ToXmlContentHandler.java (working copy) @@ -22,6 +22,7 @@ import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; +import java.nio.charset.StandardCharsets; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; @@ -98,13 +99,8 @@ * @param stream XML output stream */ public ToXmlContentHandler(OutputStream stream) { - try { - this.writer = new OutputStreamWriter(stream, "UTF-8"); - this.declaration = "version=\"1.0\" encoding=\"UTF-8\""; - } catch (UnsupportedEncodingException e) { - // should never happen - throw new IllegalStateException("UTF-8 is not supported!"); - } + this.writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8); + this.declaration = "version=\"1.0\" encoding=\"UTF-8\""; } /** Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Base64.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Base64.java (revision 1819267) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Base64.java (working copy) @@ -26,6 +26,7 @@ import java.io.StringWriter; import java.io.Writer; import java.io.BufferedWriter; +import java.nio.charset.StandardCharsets; /** * Base64 provides Base64 encoding/decoding of strings and streams. @@ -239,7 +240,7 @@ public static String encode(String data) { try { StringWriter buffer = new StringWriter(); - byte[] b = data.getBytes("UTF-8"); + byte[] b = data.getBytes(StandardCharsets.UTF_8); encode(b, 0, b.length, buffer); return buffer.toString(); } catch (IOException e) { // should never happen @@ -261,7 +262,7 @@ try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); decode(data, buffer); - return new String(buffer.toByteArray(), "UTF-8"); + return new String(buffer.toByteArray(), StandardCharsets.UTF_8); } catch (IllegalArgumentException e) { return data; } catch (IOException e) { // should never happen Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java (revision 1819267) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java (working copy) @@ -18,6 +18,7 @@ import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; @@ -350,24 +351,20 @@ * @throws NullPointerException if string is null. */ public static String escape(String string, char escape, boolean isPath) { - try { - BitSet validChars = isPath ? URISaveEx : URISave; - byte[] bytes = string.getBytes("utf-8"); - StringBuilder out = new StringBuilder(bytes.length); - for (byte aByte : bytes) { - int c = aByte & 0xff; - if (validChars.get(c) && c != escape) { - out.append((char) c); - } else { - out.append(escape); - out.append(hexTable[(c >> 4) & 0x0f]); - out.append(hexTable[(c) & 0x0f]); - } + BitSet validChars = isPath ? URISaveEx : URISave; + byte[] bytes = string.getBytes(StandardCharsets.UTF_8); + StringBuilder out = new StringBuilder(bytes.length); + for (byte aByte : bytes) { + int c = aByte & 0xff; + if (validChars.get(c) && c != escape) { + out.append((char) c); + } else { + out.append(escape); + out.append(hexTable[(c >> 4) & 0x0f]); + out.append(hexTable[(c) & 0x0f]); } - return out.toString(); - } catch (UnsupportedEncodingException e) { - throw new InternalError(e.toString()); } + return out.toString(); } /** @@ -413,31 +410,26 @@ * escape character */ public static String unescape(String string, char escape) { - try { - byte[] utf8 = string.getBytes("utf-8"); + byte[] utf8 = string.getBytes(StandardCharsets.UTF_8); - // Check whether escape occurs at invalid position - if ((utf8.length >= 1 && utf8[utf8.length - 1] == escape) || - (utf8.length >= 2 && utf8[utf8.length - 2] == escape)) { - throw new IllegalArgumentException("Premature end of escape sequence at end of input"); - } + // Check whether escape occurs at invalid position + if ((utf8.length >= 1 && utf8[utf8.length - 1] == escape) || + (utf8.length >= 2 && utf8[utf8.length - 2] == escape)) { + throw new IllegalArgumentException("Premature end of escape sequence at end of input"); + } - ByteArrayOutputStream out = new ByteArrayOutputStream(utf8.length); - for (int k = 0; k < utf8.length; k++) { - byte b = utf8[k]; - if (b == escape) { - out.write((decodeDigit(utf8[++k]) << 4) + decodeDigit(utf8[++k])); - } - else { - out.write(b); - } + ByteArrayOutputStream out = new ByteArrayOutputStream(utf8.length); + for (int k = 0; k < utf8.length; k++) { + byte b = utf8[k]; + if (b == escape) { + out.write((decodeDigit(utf8[++k]) << 4) + decodeDigit(utf8[++k])); } + else { + out.write(b); + } + } - return new String(out.toByteArray(), "utf-8"); - } - catch (UnsupportedEncodingException e) { - throw new InternalError(e.toString()); - } + return new String(out.toByteArray(), StandardCharsets.UTF_8); } /** Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java (revision 1819267) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java (working copy) @@ -52,6 +52,7 @@ import java.io.OutputStream; import java.io.BufferedOutputStream; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -738,7 +739,7 @@ } else { String textVal = value.getString(); if (enforceBase64) { - byte bytes[] = textVal.getBytes("UTF-8"); + byte bytes[] = textVal.getBytes(StandardCharsets.UTF_8); Base64.encode(bytes, 0, bytes.length, writer); } else { Index: jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/value/AbstractValue.java =================================================================== --- jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/value/AbstractValue.java (revision 1819267) +++ jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/value/AbstractValue.java (working copy) @@ -23,6 +23,7 @@ import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.Calendar; import javax.jcr.Binary; @@ -97,31 +98,27 @@ * by {@link #getString()}. Subclasses */ public Binary getBinary() throws RepositoryException { - try { - final byte[] value = getString().getBytes("UTF-8"); - return new Binary() { - public int read(byte[] b, long position) { - if (position >= value.length) { - return -1; - } else { - int p = (int) position; - int n = Math.min(b.length, value.length - p); - System.arraycopy(value, p, b, 0, n); - return n; - } + final byte[] value = getString().getBytes(StandardCharsets.UTF_8); + return new Binary() { + public int read(byte[] b, long position) { + if (position >= value.length) { + return -1; + } else { + int p = (int) position; + int n = Math.min(b.length, value.length - p); + System.arraycopy(value, p, b, 0, n); + return n; } - public InputStream getStream() { - return new ByteArrayInputStream(value); - } - public long getSize() { - return value.length; - } - public void dispose() { - } - }; - } catch (UnsupportedEncodingException e) { - throw new RepositoryException("UTF-8 is not supported", e); - } + } + public InputStream getStream() { + return new ByteArrayInputStream(value); + } + public long getSize() { + return value.length; + } + public void dispose() { + } + }; } /** Index: jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/value/BinaryValue.java =================================================================== --- jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/value/BinaryValue.java (revision 1819267) +++ jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/value/BinaryValue.java (working copy) @@ -22,6 +22,7 @@ import java.io.Reader; import java.io.Serializable; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.Calendar; import javax.jcr.Binary; @@ -72,7 +73,7 @@ try { InputStream stream = value.getStream(); try { - Reader reader = new InputStreamReader(stream, "UTF-8"); + Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8); StringBuilder builder = new StringBuilder(); char[] buffer = new char[1024]; int n = reader.read(buffer); Index: jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java =================================================================== --- jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java (revision 1819267) +++ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java (working copy) @@ -30,6 +30,7 @@ import java.util.TimeZone; import java.math.BigDecimal; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.io.InputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -345,7 +346,7 @@ try { InputStream stream = getStream(); try { - Reader reader = new InputStreamReader(stream, "UTF-8"); + Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8); Writer writer = new StringWriter(); char[] buffer = new char[1024]; int n = reader.read(buffer); Index: jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/QValueValue.java =================================================================== --- jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/QValueValue.java (revision 1819267) +++ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/QValueValue.java (working copy) @@ -17,10 +17,10 @@ package org.apache.jackrabbit.spi.commons.value; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.Calendar; import javax.jcr.Binary; @@ -105,31 +105,27 @@ if (getType() == PropertyType.NAME || getType() == PropertyType.PATH) { // qualified name/path value needs to be resolved, // delegate conversion to getString() method - try { - final byte[] value = getString().getBytes("UTF-8"); - return new Binary() { - public int read(byte[] b, long position) { - if (position >= value.length) { - return -1; - } else { - int p = (int) position; - int n = Math.min(b.length, value.length - p); - System.arraycopy(value, p, b, 0, n); - return n; - } + final byte[] value = getString().getBytes(StandardCharsets.UTF_8); + return new Binary() { + public int read(byte[] b, long position) { + if (position >= value.length) { + return -1; + } else { + int p = (int) position; + int n = Math.min(b.length, value.length - p); + System.arraycopy(value, p, b, 0, n); + return n; } - public InputStream getStream() { - return new ByteArrayInputStream(value); - } - public long getSize() { - return value.length; - } - public void dispose() { - } - }; - } catch (UnsupportedEncodingException ex) { - throw new RepositoryException("UTF-8 is not supported", ex); - } + } + public InputStream getStream() { + return new ByteArrayInputStream(value); + } + public long getSize() { + return value.length; + } + public void dispose() { + } + }; } else { return qvalue.getBinary(); } @@ -163,11 +159,7 @@ if (stream == null) { if (getType() == PropertyType.NAME || getType() == PropertyType.PATH) { // qualified name/path value needs to be resolved - try { - stream = new ByteArrayInputStream(getString().getBytes("UTF-8")); - } catch (UnsupportedEncodingException ex) { - throw new RepositoryException("UTF-8 is not supported", ex); - } + stream = new ByteArrayInputStream(getString().getBytes(StandardCharsets.UTF_8)); } else { stream = qvalue.getStream(); } Index: jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java =================================================================== --- jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java (revision 1819267) +++ jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java (working copy) @@ -42,6 +42,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.Locale; /** @@ -141,7 +142,7 @@ // JCR-2636: Need to use an explicit OutputStreamWriter // instead of relying on the built-in UTF-8 serialization // to avoid problems with surrogate pairs on Sun JRE 1.5. - Writer writer = new OutputStreamWriter(out, "UTF-8"); + Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); DomUtil.transformDocument(doc, writer); writer.flush(); Index: jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/util/EncodeUtil.java =================================================================== --- jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/util/EncodeUtil.java (revision 1819267) +++ jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/util/EncodeUtil.java (working copy) @@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.BitSet; /** @@ -126,24 +127,20 @@ * @throws NullPointerException if string is null. */ private static String escape(String string, char escape, boolean isPath) { - try { - BitSet validChars = isPath ? URISaveEx : URISave; - byte[] bytes = string.getBytes("utf-8"); - StringBuffer out = new StringBuffer(bytes.length); - for (byte aByte : bytes) { - int c = aByte & 0xff; - if (validChars.get(c) && c != escape) { - out.append((char) c); - } else { - out.append(escape); - out.append(hexTable[(c >> 4) & 0x0f]); - out.append(hexTable[(c) & 0x0f]); - } + BitSet validChars = isPath ? URISaveEx : URISave; + byte[] bytes = string.getBytes(StandardCharsets.UTF_8); + StringBuffer out = new StringBuffer(bytes.length); + for (byte aByte : bytes) { + int c = aByte & 0xff; + if (validChars.get(c) && c != escape) { + out.append((char) c); + } else { + out.append(escape); + out.append(hexTable[(c >> 4) & 0x0f]); + out.append(hexTable[(c) & 0x0f]); } - return out.toString(); - } catch (UnsupportedEncodingException e) { - throw new InternalError(e.toString()); } + return out.toString(); } /** @@ -178,31 +175,26 @@ * escape character */ private static String unescape(String string, char escape) { - try { - byte[] utf8 = string.getBytes("utf-8"); + byte[] utf8 = string.getBytes(StandardCharsets.UTF_8); - // Check whether escape occurs at invalid position - if ((utf8.length >= 1 && utf8[utf8.length - 1] == escape) || - (utf8.length >= 2 && utf8[utf8.length - 2] == escape)) { - throw new IllegalArgumentException("Premature end of escape sequence at end of input"); - } + // Check whether escape occurs at invalid position + if ((utf8.length >= 1 && utf8[utf8.length - 1] == escape) || + (utf8.length >= 2 && utf8[utf8.length - 2] == escape)) { + throw new IllegalArgumentException("Premature end of escape sequence at end of input"); + } - ByteArrayOutputStream out = new ByteArrayOutputStream(utf8.length); - for (int k = 0; k < utf8.length; k++) { - byte b = utf8[k]; - if (b == escape) { - out.write((decodeDigit(utf8[++k]) << 4) + decodeDigit(utf8[++k])); - } - else { - out.write(b); - } + ByteArrayOutputStream out = new ByteArrayOutputStream(utf8.length); + for (int k = 0; k < utf8.length; k++) { + byte b = utf8[k]; + if (b == escape) { + out.write((decodeDigit(utf8[++k]) << 4) + decodeDigit(utf8[++k])); } + else { + out.write(b); + } + } - return new String(out.toByteArray(), "utf-8"); - } - catch (UnsupportedEncodingException e) { - throw new InternalError(e.toString()); - } + return new String(out.toByteArray(), StandardCharsets.UTF_8); } private static byte decodeDigit(byte b) {