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.ByteArrayInputStream;
20 import java.io.FilterInputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23
24 import org.springframework.util.Assert;
25
26 import org.jivesoftware.smack.packet.Message;
27
28
29
30
31
32
33
34
35 class MessageInputStream extends FilterInputStream {
36
37 MessageInputStream(Message message, String encoding) throws IOException {
38 super(createInputStream(message, encoding));
39 }
40
41 private static InputStream createInputStream(Message message, String encoding) throws IOException {
42 Assert.notNull(message, "'message' must not be null");
43 Assert.notNull(encoding, "'encoding' must not be null");
44 String text = message.getBody();
45 byte[] contents = text != null ? text.getBytes(encoding) : new byte[0];
46 return new ByteArrayInputStream(contents);
47 }
48
49
50 }