View Javadoc

1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.transport.jms;
18  
19  import java.io.IOException;
20  import java.io.OutputStream;
21  import javax.jms.BytesMessage;
22  import javax.jms.JMSException;
23  
24  import org.springframework.util.Assert;
25  
26  /**
27   * Output stream that wraps a {@link BytesMessage}.
28   *
29   * @author Arjen Poutsma
30   * @since 1.5.0
31   */
32  class BytesMessageOutputStream extends OutputStream {
33  
34      private final BytesMessage message;
35  
36      BytesMessageOutputStream(BytesMessage message) {
37          Assert.notNull(message, "'message' must not be null");
38          this.message = message;
39      }
40  
41      @Override
42      public void write(byte b[]) throws IOException {
43          try {
44              message.writeBytes(b);
45          }
46          catch (JMSException ex) {
47              throw new JmsTransportException(ex);
48          }
49      }
50  
51      @Override
52      public void write(byte b[], int off, int len) throws IOException {
53          try {
54              message.writeBytes(b, off, len);
55          }
56          catch (JMSException ex) {
57              throw new JmsTransportException(ex);
58          }
59      }
60  
61      @Override
62      public void write(int b) throws IOException {
63          try {
64              message.writeByte((byte) b);
65          }
66          catch (JMSException ex) {
67              throw new JmsTransportException(ex);
68          }
69      }
70  }