📄 xbbytesmessage.java
字号:
} } public double readDouble() throws JMSException { getterCheck("readDouble"); try { this.dataIs.mark(10); return this.dataIs.readDouble(); } catch (EOFException ex) { throw new MessageEOFException(ME + ".readDouble: " + ex.getMessage(), ErrorCode.USER_MESSAGE_INVALID.getErrorCode()); } catch (IOException ex) { resetDataStream(); throw new JMSException(ME + ".readDouble: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public String readUTF() throws JMSException { getterCheck("readUTF"); try { this.dataIs.mark(this.content == null ? 10 : this.content.length); return this.dataIs.readUTF(); } catch (EOFException ex) { throw new MessageEOFException(ME + ".readUTF: " + ex.getMessage(), ErrorCode.USER_MESSAGE_INVALID.getErrorCode()); } catch (IOException ex) { resetDataStream(); throw new JMSException(ME + ".readUTF: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public String readString() throws JMSException { getterCheck("readString"); return readUTF(); } public int readBytes(byte[] value) throws JMSException { return readBytes(value, value.length); } public Object readObject() throws JMSException { getterCheck("readObject"); try { this.dataIs.mark(this.content == null ? 10 : this.content.length); /* * We can not use ObjectStream as a decorator around ByteArrayOutputStream since * it puts 4 bytes in the stream, so we wrap the object inside a pair of * <int, byte[]> and serialize that */ int size = this.dataIs.readInt(); byte[] valAsBytes = new byte[size]; this.dataIs.read(valAsBytes); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(valAsBytes)); return ois.readObject(); } catch (EOFException ex) { throw new MessageEOFException(ME + ".readObject: " + ex.getMessage(), ErrorCode.USER_MESSAGE_INVALID.getErrorCode()); } catch (ClassNotFoundException ex) { throw new XBException(ex, "readObject: the class was not found"); } catch (IOException ex) { resetDataStream(); throw new XBException(ex, "readObject: an IOException occured"); } } public int readBytes(byte[] value, int length) throws JMSException { getterCheck("readBytes"); if (length < 0 || length > value.length) throw new IndexOutOfBoundsException(ME + ".readBytes: length='" + length + "' array length='" + value.length + "'"); if (this.streamEnded) return -1; try { this.dataIs.mark(value.length); int size = 0; int offset = 0; int sum = 0; // while ((size = this.dataIs.available()) > 0) { while ((size = this.bais.available()) > 0) { if (offset + size > length) size = length - offset; if (size < 1) break; sum += this.dataIs.read(value, offset, size); } if (sum < length) this.streamEnded = true; return sum; } catch (EOFException ex) { throw new MessageEOFException(ME + ".readDouble: " + ex.getMessage(), ErrorCode.USER_MESSAGE_INVALID.getErrorCode()); } catch (IOException ex) { resetDataStream(); throw new JMSException(ME + ".readBytes: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeBoolean(boolean value) throws JMSException { setterCheck("writeBoolean"); try { this.dataOs.writeBoolean(value); } catch (IOException ex) { throw new JMSException(ME + ".writeBoolean: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeByte(byte value) throws JMSException { setterCheck("writeByte"); try { this.dataOs.writeByte(value); } catch (IOException ex) { throw new JMSException(ME + ".writeByte: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeShort(short value) throws JMSException { setterCheck("writeShort"); try { this.dataOs.writeShort(value); } catch (IOException ex) { throw new JMSException(ME + ".writeShort: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeChar(char value) throws JMSException { setterCheck("writeChar"); try { this.dataOs.writeChar(value); } catch (IOException ex) { throw new JMSException(ME + ".writeChar: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeInt(int value) throws JMSException { setterCheck("writeInt"); try { this.dataOs.writeInt(value); } catch (IOException ex) { throw new JMSException(ME + ".writeInt: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeLong(long value) throws JMSException { setterCheck("writeLong"); try { this.dataOs.writeLong(value); } catch (IOException ex) { throw new JMSException(ME + ".writeLong: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeFloat(float value) throws JMSException { setterCheck("writeFloat"); try { this.dataOs.writeFloat(value); } catch (IOException ex) { throw new JMSException(ME + ".writeFloat: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeDouble(double value) throws JMSException { setterCheck("writeDouble"); try { this.dataOs.writeDouble(value); } catch (IOException ex) { throw new JMSException(ME + ".writeDouble: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeUTF(String value) throws JMSException { setterCheck("writeUTF"); if (value == null) throw new NullPointerException(ME + ".writeUTF"); try { this.dataOs.writeUTF(value); } catch (IOException ex) { throw new JMSException(ME + ".writeUTF: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeString(String value) throws JMSException { setterCheck("writeString"); if (value == null) throw new NullPointerException(ME + ".writeString"); try { this.dataOs.writeUTF(value); } catch (IOException ex) { throw new JMSException(ME + ".writeString: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeBytes(byte[] value) throws JMSException { writeBytes(value, 0, value.length); } public void writeBytes(byte[] value, int offset, int length) throws JMSException { setterCheck("writeBytes"); if (value == null) throw new NullPointerException(ME + ".writeBytes"); try { this.dataOs.write(value, offset, length); } catch (IOException ex) { throw new JMSException(ME + ".writeBytes: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public void writeObject(Object value) throws JMSException { setterCheck("writeObject"); if (value == null) throw new NullPointerException(ME + ".writeObject"); try { /* * We can not use ObjectStream as a decorator around ByteArrayOutputStream since * it puts 4 bytes in the stream, so we wrap the object inside a pair of * <int, byte[]> and serialize that */ ByteArrayOutputStream tmp = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(tmp); oos.writeObject(value); byte[] valAsBytes = tmp.toByteArray(); this.dataOs.writeInt(valAsBytes.length); this.dataOs.write(valAsBytes); } catch (IOException ex) { throw new JMSException(ME + ".writeObject: " + ex.getMessage(), ErrorCode.USER_ILLEGALARGUMENT.getErrorCode()); } } public synchronized void reset() throws JMSException { if (this.writeOnly) { this.content = this.baos.toByteArray(); } this.bais = new ByteArrayInputStream(this.content); this.dataIs = new DataInputStream(this.bais); if (!this.dataIs.markSupported()) throw new XBException(ErrorCode.INTERNAL_NOTIMPLEMENTED.getDescription(), "Mark is not supported for the stream. Can not recover in case of an IOException"); this.readOnly = true; this.writeOnly = false; this.baos = null; this.dataOs = null; } public void clearBody() throws JMSException { super.clearBody(); makeWriteable(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -