1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport.xmpp;
18
19 import java.io.ByteArrayOutputStream;
20 import java.io.FilterOutputStream;
21 import java.io.IOException;
22
23 import org.springframework.util.Assert;
24
25 import org.jivesoftware.smack.packet.Message;
26
27
28
29
30
31
32
33
34 class MessageOutputStream extends FilterOutputStream {
35
36 private final Message message;
37
38 private final String encoding;
39
40 MessageOutputStream(Message message, String encoding) {
41 super(new ByteArrayOutputStream());
42 Assert.notNull(message, "'message' must not be null");
43 Assert.notNull(encoding, "'encoding' must not be null");
44 this.message = message;
45 this.encoding = encoding;
46 }
47
48 @Override
49 public void flush() throws IOException {
50 super.flush();
51 ByteArrayOutputStream bos = (ByteArrayOutputStream) out;
52 String text = new String(bos.toByteArray(), encoding);
53 message.setBody(text);
54 }
55 }