Use StandardCharsets more
This commit is contained in:
parent
5778609a8d
commit
81956e1716
|
@ -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 {
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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())) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue