Search in sources :

Example 21 with MessageNotReadableException

use of javax.jms.MessageNotReadableException in project activemq-artemis by apache.

the class SimpleJMSStreamMessage method readFloat.

@Override
public float readFloat() throws JMSException {
    if (bodyWriteOnly) {
        throw new MessageNotReadableException("The message body is writeonly");
    }
    try {
        Object value = content.get(position);
        offset = 0;
        if (value == null) {
            throw new NullPointerException("Value is null");
        } else if (value instanceof Float) {
            position++;
            return ((Float) value).floatValue();
        } else if (value instanceof String) {
            float result = Float.parseFloat((String) value);
            position++;
            return result;
        } else {
            throw new MessageFormatException("Invalid conversion");
        }
    } catch (IndexOutOfBoundsException e) {
        throw new MessageEOFException("");
    }
}
Also used : MessageFormatException(javax.jms.MessageFormatException) MessageEOFException(javax.jms.MessageEOFException) MessageNotReadableException(javax.jms.MessageNotReadableException)

Example 22 with MessageNotReadableException

use of javax.jms.MessageNotReadableException in project activemq-artemis by apache.

the class SimpleJMSStreamMessage method readShort.

@Override
public short readShort() throws JMSException {
    if (bodyWriteOnly) {
        throw new MessageNotReadableException("The message body is writeonly");
    }
    try {
        Object value = content.get(position);
        offset = 0;
        if (value == null) {
            throw new NullPointerException("Value is null");
        } else if (value instanceof Byte) {
            position++;
            return ((Byte) value).shortValue();
        } else if (value instanceof Short) {
            position++;
            return ((Short) value).shortValue();
        } else if (value instanceof String) {
            short result = Short.parseShort((String) value);
            position++;
            return result;
        } else {
            throw new MessageFormatException("Invalid conversion");
        }
    } catch (IndexOutOfBoundsException e) {
        throw new MessageEOFException("");
    }
}
Also used : MessageFormatException(javax.jms.MessageFormatException) MessageEOFException(javax.jms.MessageEOFException) MessageNotReadableException(javax.jms.MessageNotReadableException)

Example 23 with MessageNotReadableException

use of javax.jms.MessageNotReadableException in project activemq-artemis by apache.

the class SimpleJMSStreamMessage method readBytes.

@Override
public int readBytes(final byte[] value) throws JMSException {
    if (bodyWriteOnly) {
        throw new MessageNotReadableException("The message body is writeonly");
    }
    try {
        Object myObj = content.get(position);
        if (myObj == null) {
            throw new NullPointerException("Value is null");
        } else if (!(myObj instanceof byte[])) {
            throw new MessageFormatException("Invalid conversion");
        }
        byte[] obj = (byte[]) myObj;
        if (obj.length == 0) {
            position++;
            offset = 0;
            return 0;
        }
        if (offset >= obj.length) {
            position++;
            offset = 0;
            return -1;
        }
        if (obj.length - offset < value.length) {
            System.arraycopy(obj, offset, value, 0, obj.length);
            position++;
            offset = 0;
            return obj.length - offset;
        } else {
            System.arraycopy(obj, offset, value, 0, value.length);
            offset += value.length;
            return value.length;
        }
    } catch (IndexOutOfBoundsException e) {
        throw new MessageEOFException("");
    }
}
Also used : MessageFormatException(javax.jms.MessageFormatException) MessageEOFException(javax.jms.MessageEOFException) MessageNotReadableException(javax.jms.MessageNotReadableException)

Example 24 with MessageNotReadableException

use of javax.jms.MessageNotReadableException in project activemq-artemis by apache.

the class SimpleJMSStreamMessage method readObject.

@Override
public Object readObject() throws JMSException {
    if (bodyWriteOnly) {
        throw new MessageNotReadableException("The message body is writeonly");
    }
    try {
        Object value = content.get(position);
        position++;
        offset = 0;
        return value;
    } catch (IndexOutOfBoundsException e) {
        throw new MessageEOFException("");
    }
}
Also used : MessageEOFException(javax.jms.MessageEOFException) MessageNotReadableException(javax.jms.MessageNotReadableException)

Aggregations

MessageNotReadableException (javax.jms.MessageNotReadableException)24 MessageEOFException (javax.jms.MessageEOFException)21 MessageFormatException (javax.jms.MessageFormatException)14 MessageNotWriteableException (javax.jms.MessageNotWriteableException)3 RMQMessageFormatException (com.rabbitmq.jms.util.RMQMessageFormatException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 RMQJMSException (com.rabbitmq.jms.util.RMQJMSException)1 EOFException (java.io.EOFException)1 UTFDataFormatException (java.io.UTFDataFormatException)1 BytesMessage (javax.jms.BytesMessage)1 JMSException (javax.jms.JMSException)1 StreamMessage (javax.jms.StreamMessage)1