Revise encoding steps towards use of JDK Charset and StandardCharsets
Issue: SPR-14492
This commit is contained in:
@@ -22,6 +22,7 @@ import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@@ -70,7 +71,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
|
||||
* the {@code application/json} MIME type with {@code UTF-8} character set.
|
||||
*/
|
||||
public MappingJackson2MessageConverter() {
|
||||
super(new MimeType("application", "json", Charset.forName("UTF-8")));
|
||||
super(new MimeType("application", "json", StandardCharsets.UTF_8));
|
||||
initObjectMapper();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.messaging.converter;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
@@ -35,7 +36,7 @@ public class StringMessageConverter extends AbstractMessageConverter {
|
||||
|
||||
|
||||
public StringMessageConverter() {
|
||||
this(Charset.forName("UTF-8"));
|
||||
this(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public StringMessageConverter(Charset defaultCharset) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.messaging.simp.stomp;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -47,13 +48,10 @@ import org.springframework.util.MultiValueMap;
|
||||
*/
|
||||
public class StompDecoder {
|
||||
|
||||
static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
|
||||
|
||||
static final byte[] HEARTBEAT_PAYLOAD = new byte[] {'\n'};
|
||||
|
||||
private static final Log logger = LogFactory.getLog(StompDecoder.class);
|
||||
|
||||
|
||||
private MessageHeaderInitializer headerInitializer;
|
||||
|
||||
|
||||
@@ -202,7 +200,7 @@ public class StompDecoder {
|
||||
while (buffer.remaining() > 0 && !tryConsumeEndOfLine(buffer)) {
|
||||
command.write(buffer.get());
|
||||
}
|
||||
return new String(command.toByteArray(), UTF8_CHARSET);
|
||||
return new String(command.toByteArray(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private void readHeaders(ByteBuffer buffer, StompHeaderAccessor headerAccessor) {
|
||||
@@ -217,7 +215,7 @@ public class StompDecoder {
|
||||
headerStream.write(buffer.get());
|
||||
}
|
||||
if (headerStream.size() > 0 && headerComplete) {
|
||||
String header = new String(headerStream.toByteArray(), UTF8_CHARSET);
|
||||
String header = new String(headerStream.toByteArray(), StandardCharsets.UTF_8);
|
||||
int colonIndex = header.indexOf(':');
|
||||
if (colonIndex <= 0) {
|
||||
if (buffer.remaining() > 0) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.messaging.simp.stomp;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -81,7 +82,7 @@ public final class StompEncoder {
|
||||
else {
|
||||
StompCommand command = StompHeaderAccessor.getCommand(headers);
|
||||
Assert.notNull(command, "Missing STOMP command: " + headers);
|
||||
output.write(command.toString().getBytes(StompDecoder.UTF8_CHARSET));
|
||||
output.write(command.toString().getBytes(StandardCharsets.UTF_8));
|
||||
output.write(LF);
|
||||
writeHeaders(command, headers, payload, output);
|
||||
output.write(LF);
|
||||
@@ -132,15 +133,15 @@ public final class StompEncoder {
|
||||
}
|
||||
if (command.requiresContentLength()) {
|
||||
int contentLength = payload.length;
|
||||
output.write("content-length:".getBytes(StompDecoder.UTF8_CHARSET));
|
||||
output.write(Integer.toString(contentLength).getBytes(StompDecoder.UTF8_CHARSET));
|
||||
output.write("content-length:".getBytes(StandardCharsets.UTF_8));
|
||||
output.write(Integer.toString(contentLength).getBytes(StandardCharsets.UTF_8));
|
||||
output.write(LF);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] encodeHeaderString(String input, boolean escape) {
|
||||
String inputToUse = (escape ? escape(input) : input);
|
||||
return inputToUse.getBytes(StompDecoder.UTF8_CHARSET);
|
||||
return inputToUse.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.messaging.simp.stomp;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -441,7 +442,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
|
||||
return contentType;
|
||||
}
|
||||
Charset charset = getContentType().getCharset();
|
||||
charset = (charset != null ? charset : StompDecoder.UTF8_CHARSET);
|
||||
charset = (charset != null ? charset : StandardCharsets.UTF_8);
|
||||
return (bytes.length < 80) ?
|
||||
contentType + " payload=" + new String(bytes, charset) :
|
||||
contentType + " payload=" + new String(Arrays.copyOf(bytes, 80), charset) + "...(truncated)";
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.messaging.support;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -115,7 +116,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class MessageHeaderAccessor {
|
||||
|
||||
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
private static final MimeType[] READABLE_MIME_TYPES = new MimeType[] {
|
||||
MimeTypeUtils.APPLICATION_JSON, MimeTypeUtils.APPLICATION_XML,
|
||||
|
||||
Reference in New Issue
Block a user