diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java index e0b274c56a..58938db150 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java @@ -27,6 +27,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; import java.util.HashMap; import java.util.Map; @@ -818,7 +819,7 @@ public class Create extends InputAbstract { try (InputStream in = openStream(source)) { copy(in, out); } - return new String(out.toByteArray(), "UTF-8"); + return new String(out.toByteArray(), StandardCharsets.UTF_8); } private void write(String source) throws IOException { diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/InboundTransformer.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/InboundTransformer.java index 3a58038854..71f75c4685 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/InboundTransformer.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/InboundTransformer.java @@ -34,6 +34,8 @@ import org.apache.qpid.proton.amqp.messaging.Properties; import javax.jms.DeliveryMode; import javax.jms.JMSException; import javax.jms.Message; + +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Set; @@ -201,7 +203,7 @@ public abstract class InboundTransformer { } Binary userId = properties.getUserId(); if (userId != null) { - vendor.setJMSXUserID(jms, new String(userId.getArray(), userId.getArrayOffset(), userId.getLength(), "UTF-8")); + vendor.setJMSXUserID(jms, new String(userId.getArray(), userId.getArrayOffset(), userId.getLength(), StandardCharsets.UTF_8)); } if (properties.getTo() != null) { jms.setJMSDestination(vendor.createDestination(properties.getTo())); diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSMappingOutboundTransformer.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSMappingOutboundTransformer.java index 7babcf36fc..73dc42ba3b 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSMappingOutboundTransformer.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/converter/message/JMSMappingOutboundTransformer.java @@ -48,6 +48,7 @@ import javax.jms.TemporaryTopic; import javax.jms.TextMessage; import javax.jms.Topic; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; import java.util.Enumeration; @@ -207,7 +208,7 @@ public class JMSMappingOutboundTransformer extends OutboundTransformer { } else if (key.startsWith("JMSXUserID")) { String value = msg.getStringProperty(key); - props.setUserId(new Binary(value.getBytes("UTF-8"))); + props.setUserId(new Binary(value.getBytes(StandardCharsets.UTF_8))); } else if (key.startsWith("JMSXGroupID")) { String value = msg.getStringProperty(key); diff --git a/examples/protocols/stomp/stomp-websockets/src/main/java/org/apache/activemq/artemis/jms/example/StompWebSocketExample.java b/examples/protocols/stomp/stomp-websockets/src/main/java/org/apache/activemq/artemis/jms/example/StompWebSocketExample.java index d784e6b09a..5ee9187669 100644 --- a/examples/protocols/stomp/stomp-websockets/src/main/java/org/apache/activemq/artemis/jms/example/StompWebSocketExample.java +++ b/examples/protocols/stomp/stomp-websockets/src/main/java/org/apache/activemq/artemis/jms/example/StompWebSocketExample.java @@ -49,7 +49,7 @@ public class StompWebSocketExample { // use JMS bytes message with UTF-8 String to send a text to Stomp clients String text = "message sent from a Java application at " + new Date(); //BytesMessage message = session.createBytesMessage(); - //message.writeBytes(text.getBytes("UTF-8")); + //message.writeBytes(text.getBytes(StandardCharsets.UTF_8)); TextMessage message = session.createTextMessage(text); System.out.println("Sent message: " + text); System.out.println("Open up the chat/index.html file in a browser and press enter"); diff --git a/examples/protocols/stomp/stomp/src/main/java/org/apache/activemq/artemis/jms/example/StompExample.java b/examples/protocols/stomp/stomp/src/main/java/org/apache/activemq/artemis/jms/example/StompExample.java index e7ea406f18..78fed5e51c 100644 --- a/examples/protocols/stomp/stomp/src/main/java/org/apache/activemq/artemis/jms/example/StompExample.java +++ b/examples/protocols/stomp/stomp/src/main/java/org/apache/activemq/artemis/jms/example/StompExample.java @@ -123,7 +123,7 @@ public class StompExample { int nbytes = inputStream.read(bytes); byte[] data = new byte[nbytes]; System.arraycopy(bytes, 0, data, 0, data.length); - String resp = new String(data, "UTF-8"); + String resp = new String(data, StandardCharsets.UTF_8); System.out.println("Got response from server: " + resp); return resp; } diff --git a/examples/protocols/stomp/stomp1.2/src/main/java/org/apache/activemq/artemis/jms/example/StompExample.java b/examples/protocols/stomp/stomp1.2/src/main/java/org/apache/activemq/artemis/jms/example/StompExample.java index 116e464dd5..318de16f8d 100644 --- a/examples/protocols/stomp/stomp1.2/src/main/java/org/apache/activemq/artemis/jms/example/StompExample.java +++ b/examples/protocols/stomp/stomp1.2/src/main/java/org/apache/activemq/artemis/jms/example/StompExample.java @@ -19,6 +19,7 @@ package org.apache.activemq.artemis.jms.example; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; +import java.nio.charset.StandardCharsets; import javax.jms.Connection; import javax.jms.ConnectionFactory; @@ -111,7 +112,7 @@ public class StompExample { } private static void sendFrame(Socket socket, String data) throws Exception { - byte[] bytes = data.getBytes("UTF-8"); + byte[] bytes = data.getBytes(StandardCharsets.UTF_8); OutputStream outputStream = socket.getOutputStream(); for (int i = 0; i < bytes.length; i++) { outputStream.write(bytes[i]); @@ -127,7 +128,7 @@ public class StompExample { byte[] data = new byte[size]; System.arraycopy(buffer, 0, data, 0, size); - String frame = new String(data, "UTF-8"); + String frame = new String(data, StandardCharsets.UTF_8); return frame; } } diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageCompressionTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageCompressionTest.java index 4a3ba4211b..01dbe6c225 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageCompressionTest.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageCompressionTest.java @@ -17,6 +17,7 @@ package org.apache.activemq.command; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import javax.jms.BytesMessage; import javax.jms.JMSException; @@ -83,10 +84,10 @@ public class MessageCompressionTest extends TestCase { sendTestBytesMessage(factory, TEXT); ActiveMQBytesMessage message = receiveTestBytesMessage(factory); int compressedSize = message.getContent().getLength(); - byte[] bytes = new byte[TEXT.getBytes("UTF8").length]; + byte[] bytes = new byte[TEXT.getBytes(StandardCharsets.UTF_8).length]; message.readBytes(bytes); assertTrue(message.readBytes(new byte[255]) == -1); - String rcvString = new String(bytes, "UTF8"); + String rcvString = new String(bytes, StandardCharsets.UTF_8); assertEquals(TEXT, rcvString); assertTrue(message.isCompressed()); @@ -326,7 +327,7 @@ public class MessageCompressionTest extends TestCase { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(queue); BytesMessage bytesMessage = session.createBytesMessage(); - bytesMessage.writeBytes(message.getBytes("UTF8")); + bytesMessage.writeBytes(message.getBytes(StandardCharsets.UTF_8)); producer.send(bytesMessage); connection.close(); } diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/network/CompressionOverNetworkTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/network/CompressionOverNetworkTest.java index d95a82ba91..73cecb885d 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/network/CompressionOverNetworkTest.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/network/CompressionOverNetworkTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -136,7 +137,7 @@ public class CompressionOverNetworkTest { payload.append(UUID.randomUUID().toString()); } - byte[] bytes = payload.toString().getBytes("UTF-8"); + byte[] bytes = payload.toString().getBytes(StandardCharsets.UTF_8); BytesMessage test = localSession.createBytesMessage(); test.writeBytes(bytes); diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/usage/StoreUsageLimitsTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/usage/StoreUsageLimitsTest.java index 49d95fd533..72dcd01138 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/usage/StoreUsageLimitsTest.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/usage/StoreUsageLimitsTest.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import org.apache.activemq.EmbeddedBrokerTestSupport; import org.apache.activemq.broker.BrokerService; @@ -56,7 +57,7 @@ public class StoreUsageLimitsTest extends EmbeddedBrokerTestSupport { boolean foundUsage = false; try { - br = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"))); + br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)); String line = null; while ((line = br.readLine()) != null) { if (line.contains(new String(Long.toString(Long.MAX_VALUE / (1024 * 1024)))) && line.contains(limitsLogLevel.toUpperCase())) { diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/usecases/RequestReplyNoAdvisoryNetworkTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/usecases/RequestReplyNoAdvisoryNetworkTest.java index 0823a58990..b4960be4bd 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/usecases/RequestReplyNoAdvisoryNetworkTest.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/usecases/RequestReplyNoAdvisoryNetworkTest.java @@ -24,6 +24,7 @@ import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Vector; @@ -111,7 +112,7 @@ public class RequestReplyNoAdvisoryNetworkTest extends JmsMultipleBrokersTestSup @Override public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(xmlConfigString.replace("%HOST%", url.getFile()).getBytes("UTF-8")); + return new ByteArrayInputStream(xmlConfigString.replace("%HOST%", url.getFile()).getBytes(StandardCharsets.UTF_8)); } }; } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/interop/CompressedInteropTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/interop/CompressedInteropTest.java index 2123f531ea..b0a1237652 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/interop/CompressedInteropTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/interop/CompressedInteropTest.java @@ -22,6 +22,8 @@ import org.apache.activemq.command.ActiveMQDestination; import org.junit.Before; import org.junit.Test; +import java.nio.charset.StandardCharsets; + import javax.jms.BytesMessage; import javax.jms.Connection; import javax.jms.MapMessage; @@ -215,11 +217,11 @@ public class CompressedInteropTest extends BasicOpenWireTest { private void receiveBytesMessageUsingCore() throws Exception { BytesMessage bytesMessage = (BytesMessage) receiveMessageUsingCore(); - byte[] bytes = new byte[TEXT.getBytes("UTF8").length]; + byte[] bytes = new byte[TEXT.getBytes(StandardCharsets.UTF_8).length]; bytesMessage.readBytes(bytes); assertTrue(bytesMessage.readBytes(new byte[255]) == -1); - String rcvString = new String(bytes, "UTF8"); + String rcvString = new String(bytes, StandardCharsets.UTF_8); assertEquals(TEXT, rcvString); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/interop/GeneralInteropTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/interop/GeneralInteropTest.java index c186ed5e77..f82f112431 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/interop/GeneralInteropTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/interop/GeneralInteropTest.java @@ -35,6 +35,7 @@ import javax.jms.Session; import javax.jms.StreamMessage; import javax.jms.TextMessage; import java.io.Serializable; +import java.nio.charset.StandardCharsets; /** * This test covers interactions between core clients and @@ -132,7 +133,7 @@ public class GeneralInteropTest extends BasicOpenWireTest { assertEquals("hello streammessage", streamMessage.readString()); //bytes messages - final byte[] bytesData = text.getBytes("UTF-8"); + final byte[] bytesData = text.getBytes(StandardCharsets.UTF_8); sendBytesMessageUsingCoreJms(queueName, bytesData); BytesMessage bytesMessage = (BytesMessage) consumer.receive(5000); @@ -441,7 +442,7 @@ public class GeneralInteropTest extends BasicOpenWireTest { assertEquals("hello streammessage", streamMessage.readString()); //bytes messages - final byte[] bytesData = text.getBytes("UTF-8"); + final byte[] bytesData = text.getBytes(StandardCharsets.UTF_8); sendBytesMessageUsingOpenWire(bytesData); BytesMessage bytesMessage = (BytesMessage) coreConsumer.receive(5000); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java index 4d900babce..d665cc2539 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java @@ -18,7 +18,6 @@ package org.apache.activemq.artemis.tests.integration.stomp; import java.net.URI; import java.net.URISyntaxException; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; @@ -148,7 +147,7 @@ public class StompOverWebsocketTest extends StompTest { protected WebSocketFrame createFrame(String msg) { if (useBinaryFrames) { - return new BinaryWebSocketFrame(Unpooled.copiedBuffer(msg, Charset.forName("UTF-8"))); + return new BinaryWebSocketFrame(Unpooled.copiedBuffer(msg, StandardCharsets.UTF_8)); } else { return new TextWebSocketFrame(msg); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/vertx/ActiveMQVertxUnitTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/vertx/ActiveMQVertxUnitTest.java index c1ffec5b76..e64bfa8f5c 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/vertx/ActiveMQVertxUnitTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/vertx/ActiveMQVertxUnitTest.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.tests.integration.vertx; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; @@ -163,7 +164,7 @@ public class ActiveMQVertxUnitTest extends ActiveMQTestBase { assertEquals(greeting, body); //send a Buffer message - final byte[] content = greeting.getBytes("UTF-8"); + final byte[] content = greeting.getBytes(StandardCharsets.UTF_8); Buffer buffer = new Buffer(content); vertx.eventBus().send(incomingVertxAddress1, buffer); @@ -383,7 +384,7 @@ public class ActiveMQVertxUnitTest extends ActiveMQTestBase { handler.checkStringMessageReceived(greeting); //send a Buffer message - final byte[] content = greeting.getBytes("UTF-8"); + final byte[] content = greeting.getBytes(StandardCharsets.UTF_8); Buffer buffer = new Buffer(content); vertx.eventBus().send(incomingVertxAddress2, buffer); @@ -395,7 +396,7 @@ public class ActiveMQVertxUnitTest extends ActiveMQTestBase { handler.checkBooleanMessageReceived(boolValue); - byte[] byteArray = greeting.getBytes("UTF-8"); + byte[] byteArray = greeting.getBytes(StandardCharsets.UTF_8); vertx.eventBus().send(incomingVertxAddress2, byteArray); handler.checkByteArrayMessageReceived(byteArray); @@ -517,7 +518,7 @@ public class ActiveMQVertxUnitTest extends ActiveMQTestBase { handler2.checkStringMessageReceived(greeting); //send a Buffer message - final byte[] content = greeting.getBytes("UTF-8"); + final byte[] content = greeting.getBytes(StandardCharsets.UTF_8); Buffer buffer = new Buffer(content); vertx.eventBus().send(incomingVertxAddress3, buffer); @@ -531,7 +532,7 @@ public class ActiveMQVertxUnitTest extends ActiveMQTestBase { handler1.checkBooleanMessageReceived(boolValue); handler2.checkBooleanMessageReceived(boolValue); - byte[] byteArray = greeting.getBytes("UTF-8"); + byte[] byteArray = greeting.getBytes(StandardCharsets.UTF_8); vertx.eventBus().send(incomingVertxAddress3, byteArray); handler1.checkByteArrayMessageReceived(byteArray);