Simplify conversion of ByteArrayOutputStream to String
Closes gh-24785
This commit is contained in:
parent
62c545d0ed
commit
65aa2d03f0
|
@ -88,7 +88,7 @@ class SortedProperties extends Properties {
|
||||||
public void store(OutputStream out, String comments) throws IOException {
|
public void store(OutputStream out, String comments) throws IOException {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
super.store(baos, (this.omitComments ? null : comments));
|
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)) {
|
for (String line : contents.split(EOL)) {
|
||||||
if (!(this.omitComments && line.startsWith("#"))) {
|
if (!(this.omitComments && line.startsWith("#"))) {
|
||||||
out.write((line + EOL).getBytes(StandardCharsets.ISO_8859_1));
|
out.write((line + EOL).getBytes(StandardCharsets.ISO_8859_1));
|
||||||
|
|
|
@ -90,7 +90,7 @@ class SortedProperties extends Properties {
|
||||||
public void store(OutputStream out, @Nullable String comments) throws IOException {
|
public void store(OutputStream out, @Nullable String comments) throws IOException {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
super.store(baos, (this.omitComments ? null : comments));
|
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)) {
|
for (String line : contents.split(EOL)) {
|
||||||
if (!(this.omitComments && line.startsWith("#"))) {
|
if (!(this.omitComments && line.startsWith("#"))) {
|
||||||
out.write((line + EOL).getBytes(StandardCharsets.ISO_8859_1));
|
out.write((line + EOL).getBytes(StandardCharsets.ISO_8859_1));
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class ProtobufMessageConverter extends AbstractMessageConverter {
|
||||||
else if (this.protobufFormatSupport != null) {
|
else if (this.protobufFormatSupport != null) {
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
this.protobufFormatSupport.print(message, outputStream, contentType, charset);
|
this.protobufFormatSupport.print(message, outputStream, contentType, charset);
|
||||||
payload = new String(outputStream.toByteArray(), charset);
|
payload = outputStream.toString(charset.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
|
|
|
@ -252,15 +252,14 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleFrame(ByteArrayOutputStream os) {
|
private void handleFrame(ByteArrayOutputStream os) throws IOException {
|
||||||
byte[] bytes = os.toByteArray();
|
String content = os.toString(SockJsFrame.CHARSET.toString());
|
||||||
os.reset();
|
os.reset();
|
||||||
String content = new String(bytes, SockJsFrame.CHARSET);
|
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("XHR receive content: " + content);
|
logger.trace("XHR receive content: " + content);
|
||||||
}
|
}
|
||||||
if (!PRELUDE.equals(content)) {
|
if (!PRELUDE.equals(content)) {
|
||||||
this.sockJsSession.handleFrame(new String(bytes, SockJsFrame.CHARSET));
|
this.sockJsSession.handleFrame(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue