javax.jms.StreamMessage#readBytes ( )源码实例Demo

下面列出了javax.jms.StreamMessage#readBytes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: localization_nifi   文件: JmsFactory.java
private static byte[] getMessageBytes(StreamMessage message) throws JMSException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();

    byte[] byteBuffer = new byte[4096];
    int byteCount;
    while ((byteCount = message.readBytes(byteBuffer)) != -1) {
        baos.write(byteBuffer, 0, byteCount);
    }

    try {
        baos.close();
    } catch (final IOException ioe) {
    }

    return baos.toByteArray();
}
 
@Override
protected void assertEquivalent(final Message m, final int mode, final boolean redelivery) throws JMSException {
   super.assertEquivalent(m, mode, redelivery);

   StreamMessage sm = (StreamMessage) m;

   ProxyAssertSupport.assertTrue(sm.readBoolean());

   byte[] bytes = new byte[5];
   sm.readBytes(bytes);
   String s = new String(bytes);
   ProxyAssertSupport.assertEquals("jboss", s);
   ProxyAssertSupport.assertEquals(-1, sm.readBytes(bytes));

   ProxyAssertSupport.assertEquals(sm.readChar(), 'c');
   ProxyAssertSupport.assertEquals(sm.readDouble(), 1.0D, 0.0D);
   ProxyAssertSupport.assertEquals(sm.readFloat(), 2.0F, 0.0F);
   ProxyAssertSupport.assertEquals(sm.readInt(), 3);
   ProxyAssertSupport.assertEquals(sm.readLong(), 4L);
   ProxyAssertSupport.assertEquals(sm.readObject(), "object");
   ProxyAssertSupport.assertEquals(sm.readShort(), (short) 5);
   ProxyAssertSupport.assertEquals(sm.readString(), "stringvalue");
}
 
源代码3 项目: activemq-artemis   文件: StreamMessageTest.java
@Override
protected void assertEquivalent(final Message m, final int mode, final boolean redelivery) throws JMSException {
   super.assertEquivalent(m, mode, redelivery);

   StreamMessage sm = (StreamMessage) m;

   sm.reset();

   ProxyAssertSupport.assertEquals(true, sm.readBoolean());
   ProxyAssertSupport.assertEquals((byte) 3, sm.readByte());
   byte[] bytes = new byte[3];
   sm.readBytes(bytes);
   ProxyAssertSupport.assertEquals((byte) 4, bytes[0]);
   ProxyAssertSupport.assertEquals((byte) 5, bytes[1]);
   ProxyAssertSupport.assertEquals((byte) 6, bytes[2]);
   ProxyAssertSupport.assertEquals(-1, sm.readBytes(bytes));
   ProxyAssertSupport.assertEquals((char) 7, sm.readChar());
   ProxyAssertSupport.assertEquals(new Double(8.0), new Double(sm.readDouble()));
   ProxyAssertSupport.assertEquals(new Float(9.0), new Float(sm.readFloat()));
   ProxyAssertSupport.assertEquals(10, sm.readInt());
   ProxyAssertSupport.assertEquals(11L, sm.readLong());
   ProxyAssertSupport.assertEquals("this is an object", sm.readObject());
   ProxyAssertSupport.assertEquals((short) 12, sm.readShort());
   ProxyAssertSupport.assertEquals("this is a String", sm.readString());
}
 
源代码4 项目: nifi   文件: JmsFactory.java
private static byte[] getMessageBytes(StreamMessage message) throws JMSException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();

    byte[] byteBuffer = new byte[4096];
    int byteCount;
    while ((byteCount = message.readBytes(byteBuffer)) != -1) {
        baos.write(byteBuffer, 0, byteCount);
    }

    try {
        baos.close();
    } catch (final IOException ioe) {
    }

    return baos.toByteArray();
}
 
源代码5 项目: jadira   文件: FatalJmsExceptionMessageCreator.java
private static byte[] extractByteArrayFromMessage(StreamMessage message) throws JMSException {

        ByteArrayOutputStream oStream = new ByteArrayOutputStream(BUFFER_CAPACITY_BYTES);

        byte[] buffer = new byte[BUFFER_CAPACITY_BYTES];

        int bufferCount = -1;

        while ((bufferCount = message.readBytes(buffer)) >= 0) {
            oStream.write(buffer, 0, bufferCount);
            if (bufferCount < BUFFER_CAPACITY_BYTES) {
                break;
            }
        }

        return oStream.toByteArray();
    }
 
源代码6 项目: activemq-artemis   文件: CompressedInteropTest.java
private void receiveStreamMessage(boolean useCore) throws Exception {
   StreamMessage streamMessage = (StreamMessage) receiveMessage(useCore);
   boolean booleanVal = streamMessage.readBoolean();
   assertTrue(booleanVal);
   byte byteVal = streamMessage.readByte();
   assertEquals((byte) 10, byteVal);
   byte[] originVal = TEXT.getBytes();
   byte[] bytesVal = new byte[originVal.length];
   streamMessage.readBytes(bytesVal);
   for (int i = 0; i < bytesVal.length; i++) {
      assertTrue(bytesVal[i] == originVal[i]);
   }
   char charVal = streamMessage.readChar();
   assertEquals('A', charVal);
   double doubleVal = streamMessage.readDouble();
   assertEquals(55.3D, doubleVal, 0.1D);
   float floatVal = streamMessage.readFloat();
   assertEquals(79.1F, floatVal, 0.1F);
   int intVal = streamMessage.readInt();
   assertEquals(37, intVal);
   long longVal = streamMessage.readLong();
   assertEquals(56652L, longVal);
   Object objectVal = streamMessage.readObject();
   Object origVal = new String("VVVV");
   assertTrue(objectVal.equals(origVal));
   short shortVal = streamMessage.readShort();
   assertEquals((short) 333, shortVal);
   String strVal = streamMessage.readString();
   assertEquals(TEXT, strVal);
}