Skip to content

Commit e42e233

Browse files
committed
Polishing
1 parent b331d65 commit e42e233

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/BufferingStompDecoderTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727

2828
import static org.junit.Assert.*;
2929

30-
3130
/**
32-
* Unit tests for {@link BufferingStompDecoder}..
31+
* Unit tests for {@link BufferingStompDecoder}.
3332
*
3433
* @author Rossen Stoyanchev
3534
* @since 4.0.3
@@ -54,7 +53,6 @@ public void basic() throws InterruptedException {
5453

5554
@Test
5655
public void oneMessageInTwoChunks() throws InterruptedException {
57-
5856
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(128);
5957
String chunk1 = "SEND\na:alpha\n\nMessage";
6058
String chunk2 = " body\0";
@@ -86,9 +84,8 @@ public void twoMessagesInOneChunk() throws InterruptedException {
8684

8785
@Test
8886
public void oneFullAndOneSplitMessageContentLength() throws InterruptedException {
89-
int contentLength = "Payload2a-Payload2b".getBytes().length;
90-
9187
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(128);
88+
int contentLength = "Payload2a-Payload2b".getBytes().length;
9289
String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\ncontent-length:" + contentLength + "\n";
9390
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1));
9491

@@ -165,7 +162,7 @@ public void oneFullAndOneSplitWithContentLengthExceedingBufferSize() throws Inte
165162
}
166163

167164
@Test(expected = StompConversionException.class)
168-
public void bufferSizeLimit() throws InterruptedException {
165+
public void bufferSizeLimit() {
169166
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(10);
170167
String payload = "SEND\na:alpha\n\nMessage body";
171168
stompDecoder.decode(toByteBuffer(payload));

spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
4141

4242
public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");
4343

44+
4445
private final Charset defaultCharset;
4546

4647
private final List<Charset> availableCharsets;
@@ -66,6 +67,7 @@ public StringHttpMessageConverter(Charset defaultCharset) {
6667
this.availableCharsets = new ArrayList<Charset>(Charset.availableCharsets().values());
6768
}
6869

70+
6971
/**
7072
* Indicates whether the {@code Accept-Charset} should be written to any outgoing request.
7173
* <p>Default is {@code true}.
@@ -74,6 +76,7 @@ public void setWriteAcceptCharset(boolean writeAcceptCharset) {
7476
this.writeAcceptCharset = writeAcceptCharset;
7577
}
7678

79+
7780
@Override
7881
public boolean supports(Class<?> clazz) {
7982
return String.class.equals(clazz);
@@ -86,10 +89,10 @@ protected String readInternal(Class<? extends String> clazz, HttpInputMessage in
8689
}
8790

8891
@Override
89-
protected Long getContentLength(String s, MediaType contentType) {
92+
protected Long getContentLength(String str, MediaType contentType) {
9093
Charset charset = getContentTypeCharset(contentType);
9194
try {
92-
return (long) s.getBytes(charset.name()).length;
95+
return (long) str.getBytes(charset.name()).length;
9396
}
9497
catch (UnsupportedEncodingException ex) {
9598
// should not occur
@@ -98,17 +101,19 @@ protected Long getContentLength(String s, MediaType contentType) {
98101
}
99102

100103
@Override
101-
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
104+
protected void writeInternal(String str, HttpOutputMessage outputMessage) throws IOException {
102105
if (this.writeAcceptCharset) {
103106
outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
104107
}
105108
Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType());
106-
StreamUtils.copy(s, charset, outputMessage.getBody());
109+
StreamUtils.copy(str, charset, outputMessage.getBody());
107110
}
108111

112+
109113
/**
110-
* Return the list of supported {@link Charset}.
111-
* <p>By default, returns {@link Charset#availableCharsets()}. Can be overridden in subclasses.
114+
* Return the list of supported {@link Charset}s.
115+
* <p>By default, returns {@link Charset#availableCharsets()}.
116+
* Can be overridden in subclasses.
112117
* @return the list of accepted charsets
113118
*/
114119
protected List<Charset> getAcceptedCharsets() {
@@ -123,4 +128,5 @@ private Charset getContentTypeCharset(MediaType contentType) {
123128
return this.defaultCharset;
124129
}
125130
}
131+
126132
}

spring-websocket/src/main/java/org/springframework/web/socket/TextMessage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public final class TextMessage extends AbstractWebSocketMessage<String> {
2828

29-
private static final Charset UTF_8 = Charset.forName("UTF-8");
29+
private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
3030

3131
private final byte[] bytes;
3232

@@ -46,7 +46,7 @@ public TextMessage(CharSequence payload) {
4646
* @param payload the non-null payload
4747
*/
4848
public TextMessage(byte[] payload) {
49-
super(new String(payload, UTF_8));
49+
super(new String(payload, UTF8_CHARSET));
5050
this.bytes = payload;
5151
}
5252

@@ -70,7 +70,7 @@ public int getPayloadLength() {
7070
}
7171

7272
public byte[] asBytes() {
73-
return (this.bytes != null ? this.bytes : getPayload().getBytes(UTF_8));
73+
return (this.bytes != null ? this.bytes : getPayload().getBytes(UTF8_CHARSET));
7474
}
7575

7676
@Override

0 commit comments

Comments
 (0)