1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport.jms;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import javax.jms.BytesMessage;
22 import javax.jms.JMSException;
23 import javax.jms.MessageEOFException;
24
25 import org.springframework.util.Assert;
26
27
28
29
30
31
32
33 class BytesMessageInputStream extends InputStream {
34
35 private final BytesMessage message;
36
37 BytesMessageInputStream(BytesMessage message) {
38 Assert.notNull(message, "'message' must not be null");
39 this.message = message;
40 }
41
42 @Override
43 public int read(byte b[]) throws IOException {
44 try {
45 return message.readBytes(b);
46 }
47 catch (JMSException ex) {
48 throw new JmsTransportException(ex);
49 }
50 }
51
52 @Override
53 public int read(byte b[], int off, int len) throws IOException {
54 if (off == 0) {
55 try {
56 return message.readBytes(b, len);
57 }
58 catch (JMSException ex) {
59 throw new JmsTransportException(ex);
60 }
61 }
62 else {
63 return super.read(b, off, len);
64 }
65 }
66
67 @Override
68 public int read() throws IOException {
69 try {
70 return message.readByte();
71 }
72 catch (MessageEOFException ex) {
73 return -1;
74 }
75 catch (JMSException ex) {
76 throw new JmsTransportException(ex);
77 }
78 }
79 }