1 7 package org.jboss.jms; 8 9 import org.jboss.jms.util.JMSTypeConversions; 10 11 import javax.jms.JMSException ; 12 import javax.jms.MessageNotReadableException ; 13 import javax.jms.StreamMessage ; 14 import java.util.ArrayList ; 15 16 21 public class StreamMessageImpl extends MessageImpl implements StreamMessage 22 { 23 private int index = 0; 24 25 public StreamMessageImpl() 26 { 27 this.type = MessageImpl.STREAM_MESSGE_NAME; 28 this.body = new ArrayList (); 29 } 30 31 public final void clearBody() 32 { 33 this.getBody().clear(); 34 this.setReadOnly(false); 35 } 36 37 public final boolean readBoolean() throws JMSException 38 { 39 this.throwExceptionIfNotReadable(); 40 boolean value = 41 JMSTypeConversions.getBoolean(this.getBody().get(this.index)); 42 this.incrementPosition(); 43 return value; 44 } 45 46 public final byte readByte() throws JMSException 47 { 48 this.throwExceptionIfNotReadable(); 49 byte value = JMSTypeConversions.getByte(this.getBody().get(this.index)); 50 this.incrementPosition(); 51 return value; 52 } 53 54 public final int readBytes(byte[] value) throws JMSException 55 { 56 this.throwExceptionIfNotReadable(); 57 value = JMSTypeConversions.getBytes(this.getBody().get(this.index)); 58 this.incrementPosition(); 59 if (value == null) 60 { 61 return -1; 62 } 63 else 64 { 65 return 0; 66 } 67 } 68 69 public final char readChar() throws JMSException 70 { 71 this.throwExceptionIfNotReadable(); 72 char value = JMSTypeConversions.getChar(this.getBody().get(this.index)); 73 this.incrementPosition(); 74 return value; 75 } 76 77 public final double readDouble() throws JMSException 78 { 79 this.throwExceptionIfNotReadable(); 80 double value = 81 JMSTypeConversions.getDouble(this.getBody().get(this.index)); 82 this.incrementPosition(); 83 return value; 84 } 85 86 public final float readFloat() throws JMSException 87 { 88 this.throwExceptionIfNotReadable(); 89 float value = 90 JMSTypeConversions.getFloat(this.getBody().get(this.index)); 91 this.incrementPosition(); 92 return value; 93 } 94 95 public final int readInt() throws JMSException 96 { 97 this.throwExceptionIfNotReadable(); 98 int value = JMSTypeConversions.getInt(this.getBody().get(this.index)); 99 this.incrementPosition(); 100 return value; 101 } 102 103 public final long readLong() throws JMSException 104 { 105 this.throwExceptionIfNotReadable(); 106 long value = JMSTypeConversions.getLong(this.getBody().get(this.index)); 107 this.incrementPosition(); 108 return value; 109 } 110 111 public final Object readObject() throws JMSException 112 { 113 this.throwExceptionIfNotReadable(); 114 Object value = 115 JMSTypeConversions.getObject(this.getBody().get(this.index)); 116 this.incrementPosition(); 117 return value; 118 } 119 120 public final short readShort() throws JMSException 121 { 122 this.throwExceptionIfNotReadable(); 123 short value = 124 JMSTypeConversions.getShort(this.getBody().get(this.index)); 125 this.incrementPosition(); 126 return value; 127 } 128 129 public final String readString() throws JMSException 130 { 131 this.throwExceptionIfNotReadable(); 132 String value = 133 JMSTypeConversions.getString(this.getBody().get(this.index)); 134 this.incrementPosition(); 135 return value; 136 } 137 138 public final void reset() 139 { 140 this.setReadOnly(true); 141 this.index = 0; 142 } 143 144 public final void writeBoolean(boolean value) throws JMSException 145 { 146 this.getBody().add(new Boolean (value)); 147 this.incrementPosition(); 148 } 149 150 public final void writeByte(byte value) throws JMSException 151 { 152 this.getBody().add(new Byte (value)); 153 this.incrementPosition(); 154 } 155 156 public final void writeBytes(byte[] value) throws JMSException 157 { 158 this.getBody().add(value); 159 this.incrementPosition(); 160 } 161 162 public final void writeBytes(byte[] value, int offset, int length) 163 throws JMSException 164 { 165 byte[] bytes = new byte[length]; 166 System.arraycopy(value, offset, bytes, 0, length); 167 this.getBody().add(bytes); 168 this.incrementPosition(); 169 } 170 171 public final void writeChar(char value) throws JMSException 172 { 173 this.getBody().add(new Character (value)); 174 this.incrementPosition(); 175 } 176 177 public final void writeDouble(double value) throws JMSException 178 { 179 this.getBody().add(new Double (value)); 180 this.incrementPosition(); 181 } 182 183 public final void writeFloat(float value) throws JMSException 184 { 185 this.getBody().add(new Float (value)); 186 this.incrementPosition(); 187 } 188 189 public final void writeInt(int value) throws JMSException 190 { 191 this.getBody().add(new Integer (value)); 192 this.incrementPosition(); 193 } 194 195 public final void writeLong(long value) throws JMSException 196 { 197 this.getBody().add(new Long (value)); 198 this.incrementPosition(); 199 } 200 201 public final void writeObject(Object value) throws JMSException 202 { 203 this.getBody().add(value); 204 this.incrementPosition(); 205 } 206 207 public final void writeShort(short value) throws JMSException 208 { 209 this.getBody().add(new Short (value)); 210 this.incrementPosition(); 211 } 212 213 public final void writeString(String value) throws JMSException 214 { 215 this.getBody().add(value); 216 this.incrementPosition(); 217 } 218 219 private ArrayList getBody() 220 { 221 return (ArrayList ) super.body; 222 } 223 224 private void incrementPosition() 225 { 226 this.index = this.index + 1; 227 } 228 229 private void throwExceptionIfNotReadable() 230 throws MessageNotReadableException 231 { 232 if (!this.isReadOnly()) 233 { 234 throw new MessageNotReadableException ("The message is in write only mode."); 235 } 236 } 237 238 } | Popular Tags |