1 28 29 package com.caucho.jms.util; 30 31 import javax.jms.BytesMessage ; 32 import javax.jms.JMSException ; 33 import java.io.IOException ; 34 import java.io.InputStream ; 35 import java.util.logging.Logger ; 36 37 40 public class BytesMessageInputStream extends InputStream 41 { 42 protected static Logger log 43 = Logger.getLogger(BytesMessageInputStream.class.getName()); 44 45 private BytesMessage _message; 46 47 public BytesMessageInputStream(BytesMessage message) 48 { 49 _message = message; 50 } 51 52 public int read() 53 throws IOException 54 { 55 try { 56 return _message.readByte(); 57 } catch (JMSException e) { 58 throw new IOException (e.toString()); 59 } 60 } 61 62 public int read(byte[] buffer, int offset, int length) 63 throws IOException 64 { 65 try { 66 if (offset == 0) 67 return _message.readBytes(buffer, length); 68 else 69 return super.read(buffer, offset, length); 70 } catch (JMSException e) { 71 throw new IOException (e.toString()); 72 } 73 } 74 75 public int read(byte[] buffer) 76 throws IOException 77 { 78 try { 79 return _message.readBytes(buffer); 80 } catch (JMSException e) { 81 throw new IOException (e.toString()); 82 } 83 } 84 } 85 | Popular Tags |