bytesmessageimpl.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 765 行 · 第 1/2 页
JAVA
765 行
} } catch (JMSException e) { throw e; } catch (RuntimeException e) { throw e; } catch (Throwable e) { throw new JMSExceptionWrapper(e); } return cb.toString(); } /** * Read a byte array object from the stream. */ public int readBytes(byte []value) throws JMSException { ReadStream is = getReadStream(); try { return is.read(value); } catch (IOException e) { throw new JMSExceptionWrapper(e); } } /** * Read a byte array object from the stream. */ public int readBytes(byte []value, int length) throws JMSException { ReadStream is = getReadStream(); try { return is.read(value, 0, length); } catch (IOException e) { throw new JMSExceptionWrapper(e); } } protected ReadStream getReadStream() throws JMSException { checkBodyReadable(); /* ejb/6a87 if (_rs == null) throw new MessageEOFException(L.l("bytes message may not be read")); */ return _rs; } /** * Clears the message and puts it into write mode. */ public void clearBody() throws JMSException { super.clearBody(); _ws = null; _tempStream = null; _rs = null; } /** * Writes a boolean to the stream. */ public void writeBoolean(boolean b) throws JMSException { try { getWriteStream().write(b ? 1 : 0); } catch (IOException e) { throw new JMSExceptionWrapper(e); } } /** * Writes a byte to the stream. */ public void writeByte(byte b) throws JMSException { try { getWriteStream().write(b); } catch (IOException e) { throw new JMSExceptionWrapper(e); } } /** * Writes a short to the stream. */ public void writeShort(short s) throws JMSException { try { WriteStream ws = getWriteStream(); ws.write(s >> 8); ws.write(s); } catch (IOException e) { throw new JMSExceptionWrapper(e); } } /** * Writes an integer to the stream. */ public void writeInt(int i) throws JMSException { try { WriteStream ws = getWriteStream(); ws.write(i >> 24); ws.write(i >> 16); ws.write(i >> 8); ws.write(i); } catch (IOException e) { throw new JMSExceptionWrapper(e); } } /** * Writes a long to the stream. */ public void writeLong(long l) throws JMSException { try { WriteStream ws = getWriteStream(); ws.write((int) (l >> 56)); ws.write((int) (l >> 48)); ws.write((int) (l >> 40)); ws.write((int) (l >> 32)); ws.write((int) (l >> 24)); ws.write((int) (l >> 16)); ws.write((int) (l >> 8)); ws.write((int) l); } catch (IOException e) { throw new JMSExceptionWrapper(e); } } /** * Writes a float to the stream. */ public void writeFloat(float f) throws JMSException { int i = Float.floatToIntBits(f); writeInt(i); } /** * Writes a double to the stream. */ public void writeDouble(double d) throws JMSException { long l = Double.doubleToLongBits(d); writeLong(l); } /** * Writes a string to the stream. */ public void writeUTF(String s) throws JMSException { try { WriteStream out = getWriteStream(); int len = s.length(); int byteLength = 0; for (int i = 0; i < len; i++) { int ch = s.charAt(0); if (ch == 0) byteLength += 2; else if (ch < 0x80) byteLength += 1; else if (ch < 0x800) byteLength += 2; else byteLength += 3; } out.write(byteLength >> 8); out.write(byteLength); for (int i = 0; i < len; i++) { int ch = s.charAt(i); if (ch == 0) { out.write(0xc0); out.write(0x80); } else if (ch < 0x80) out.write(ch); else if (ch < 0x800) { out.write(0xc0 + ((ch >> 6) & 0x1f)); out.write(0x80 + (ch & 0x3f)); } else if (ch < 0x8000) { out.write(0xe0 + ((ch >> 12) & 0x0f)); out.write(0x80 + ((ch >> 6) & 0x3f)); out.write(0x80 + (ch & 0x3f)); } } } catch (IOException e) { throw new JMSExceptionWrapper(e); } } /** * Writes a character to the stream. */ public void writeChar(char ch) throws JMSException { try { WriteStream ws = getWriteStream(); ws.write(ch >> 8); ws.write(ch); } catch (IOException e) { throw new JMSExceptionWrapper(e); } } /** * Writes a byte array to the stream. */ public void writeBytes(byte []buf) throws JMSException { writeBytes(buf, 0, buf.length); } /** * Writes a byte array to the stream. */ public void writeBytes(byte []buf, int offset, int length) throws JMSException { try { WriteStream ws = getWriteStream(); ws.write(buf, offset, length); } catch (IOException e) { throw new JMSExceptionWrapper(e); } } /** * Writes the next object. */ public void writeObject(Object obj) throws JMSException { if (obj == null) throw new NullPointerException(); else if (obj instanceof Boolean) writeBoolean(((Boolean) obj).booleanValue()); else if (obj instanceof Byte) writeByte(((Byte) obj).byteValue()); else if (obj instanceof Short) writeShort(((Short) obj).shortValue()); else if (obj instanceof Character) writeChar(((Character) obj).charValue()); else if (obj instanceof Integer) writeInt(((Integer) obj).intValue()); else if (obj instanceof Long) writeLong(((Long) obj).longValue()); else if (obj instanceof Float) writeFloat(((Float) obj).floatValue()); else if (obj instanceof Double) writeDouble(((Double) obj).doubleValue()); else if (obj instanceof String) writeUTF((String) obj); else if (obj instanceof byte[]) writeBytes((byte[]) obj); else throw new MessageFormatException(obj.getClass().getName() + ": " + String.valueOf(obj)); } public long getBodyLength() throws JMSException { checkBodyReadable(); if (_tempStream == null) return 0; else return _tempStream.getLength(); } protected WriteStream getWriteStream() throws JMSException { checkBodyWriteable(); if (_tempStream == null) _tempStream = new TempStream(); if (_ws == null) _ws = new WriteStream(_tempStream); return _ws; } public MessageImpl copy() { try { return new BytesMessageImpl(this); } catch (Exception e) { throw new RuntimeException(e); } } protected void copy(BytesMessageImpl newMsg) { super.copy(newMsg); try { if (_ws != null) _ws.flush(); if (_tempStream != null) newMsg._tempStream = _tempStream.copy(); } catch (Exception e) { log.log(Level.WARNING, e.toString(), e); } } /** * Serialize the body to an input stream. */ @Override public InputStream bodyToInputStream() throws IOException { if (_tempStream != null) return _tempStream.openReadAndSaveBuffer(); else return null; } /** * Read the body from an input stream. */ @Override public void readBody(InputStream is) throws IOException, JMSException { if (is != null) { WriteStream out = getWriteStream(); out.writeStream(is); out.close(); } reset(); } public String toString() { return "BytesMessageImpl[]"; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?