Browse Source

Simplify conversion of ByteArrayOutputStream to String

Closes gh-24785
pull/24644/head
Сергей Цыпанов 5 years ago committed by Sam Brannen
parent
commit
65aa2d03f0
  1. 2
      spring-context-indexer/src/main/java/org/springframework/context/index/processor/SortedProperties.java
  2. 2
      spring-core/src/main/java/org/springframework/core/SortedProperties.java
  3. 2
      spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java
  4. 7
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java

2
spring-context-indexer/src/main/java/org/springframework/context/index/processor/SortedProperties.java

@ -88,7 +88,7 @@ class SortedProperties extends Properties { @@ -88,7 +88,7 @@ class SortedProperties extends Properties {
public void store(OutputStream out, String comments) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
super.store(baos, (this.omitComments ? null : comments));
String contents = new String(baos.toByteArray(), StandardCharsets.ISO_8859_1);
String contents = baos.toString(StandardCharsets.ISO_8859_1.name());
for (String line : contents.split(EOL)) {
if (!(this.omitComments && line.startsWith("#"))) {
out.write((line + EOL).getBytes(StandardCharsets.ISO_8859_1));

2
spring-core/src/main/java/org/springframework/core/SortedProperties.java

@ -90,7 +90,7 @@ class SortedProperties extends Properties { @@ -90,7 +90,7 @@ class SortedProperties extends Properties {
public void store(OutputStream out, @Nullable String comments) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
super.store(baos, (this.omitComments ? null : comments));
String contents = new String(baos.toByteArray(), StandardCharsets.ISO_8859_1);
String contents = baos.toString(StandardCharsets.ISO_8859_1.name());
for (String line : contents.split(EOL)) {
if (!(this.omitComments && line.startsWith("#"))) {
out.write((line + EOL).getBytes(StandardCharsets.ISO_8859_1));

2
spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java

@ -183,7 +183,7 @@ public class ProtobufMessageConverter extends AbstractMessageConverter { @@ -183,7 +183,7 @@ public class ProtobufMessageConverter extends AbstractMessageConverter {
else if (this.protobufFormatSupport != null) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
this.protobufFormatSupport.print(message, outputStream, contentType, charset);
payload = new String(outputStream.toByteArray(), charset);
payload = outputStream.toString(charset.name());
}
}
catch (IOException ex) {

7
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java

@ -252,15 +252,14 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport { @@ -252,15 +252,14 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport {
return null;
}
private void handleFrame(ByteArrayOutputStream os) {
byte[] bytes = os.toByteArray();
private void handleFrame(ByteArrayOutputStream os) throws IOException {
String content = os.toString(SockJsFrame.CHARSET.toString());
os.reset();
String content = new String(bytes, SockJsFrame.CHARSET);
if (logger.isTraceEnabled()) {
logger.trace("XHR receive content: " + content);
}
if (!PRELUDE.equals(content)) {
this.sockJsSession.handleFrame(new String(bytes, SockJsFrame.CHARSET));
this.sockJsSession.handleFrame(content);
}
}
}

Loading…
Cancel
Save