Skip to content

Commit 1b6fb7d

Browse files
hduelmegregturn
authored andcommitted
Use a more efficient conversion from ByteArrayOutputStream to String.
Resolves #1324.
1 parent 8346d5b commit 1b6fb7d

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

spring-ws-support/src/main/java/org/springframework/ws/transport/jms/TextMessageOutputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void flush() throws IOException {
5050
super.flush();
5151
try {
5252
ByteArrayOutputStream baos = (ByteArrayOutputStream) out;
53-
String text = new String(baos.toByteArray(), encoding);
53+
String text = baos.toString(encoding);
5454
message.setText(text);
5555
} catch (JMSException ex) {
5656
throw new JmsTransportException(ex);

spring-ws-support/src/main/java/org/springframework/ws/transport/xmpp/MessageOutputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class MessageOutputStream extends FilterOutputStream {
4848
public void flush() throws IOException {
4949
super.flush();
5050
ByteArrayOutputStream bos = (ByteArrayOutputStream) out;
51-
String text = new String(bos.toByteArray(), encoding);
51+
String text = bos.toString(encoding);
5252
message.setBody(text);
5353
}
5454
}

spring-ws-support/src/test/java/org/springframework/ws/transport/jms/JmsMessageSenderIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void testSendAndReceiveQueueTextMessage() throws Exception {
171171

172172
ByteArrayOutputStream bos = new ByteArrayOutputStream();
173173
messageFactory.createMessage().writeTo(bos);
174-
final String text = new String(bos.toByteArray(), StandardCharsets.UTF_8);
174+
final String text = bos.toString(StandardCharsets.UTF_8);
175175

176176
jmsTemplate.send(request.getJMSReplyTo(), session -> {
177177

0 commit comments

Comments
 (0)