Search in sources :

Example 11 with MessageNotReadableException

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

the class SimpleJMSStreamMessage method readBoolean.

// Public --------------------------------------------------------
// StreamMessage implementation ----------------------------------
@Override
public boolean readBoolean() 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 Boolean) {
            position++;
            return ((Boolean) value).booleanValue();
        } else if (value instanceof String) {
            boolean result = Boolean.valueOf((String) value).booleanValue();
            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 12 with MessageNotReadableException

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

the class SimpleJMSStreamMessage method readInt.

@Override
public int readInt() 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).intValue();
        } else if (value instanceof Short) {
            position++;
            return ((Short) value).intValue();
        } else if (value instanceof Integer) {
            position++;
            return ((Integer) value).intValue();
        } else if (value instanceof String) {
            int result = Integer.parseInt((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 13 with MessageNotReadableException

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

the class SimpleJMSStreamMessage method readString.

@Override
public String readString() throws JMSException {
    if (bodyWriteOnly) {
        throw new MessageNotReadableException("The message body is writeonly");
    }
    try {
        Object value = content.get(position);
        offset = 0;
        if (value == null) {
            position++;
            return null;
        } else if (value instanceof Boolean) {
            position++;
            return ((Boolean) value).toString();
        } else if (value instanceof Byte) {
            position++;
            return ((Byte) value).toString();
        } else if (value instanceof Short) {
            position++;
            return ((Short) value).toString();
        } else if (value instanceof Character) {
            position++;
            return ((Character) value).toString();
        } else if (value instanceof Integer) {
            position++;
            return ((Integer) value).toString();
        } else if (value instanceof Long) {
            position++;
            return ((Long) value).toString();
        } else if (value instanceof Float) {
            position++;
            return ((Float) value).toString();
        } else if (value instanceof Double) {
            position++;
            return ((Double) value).toString();
        } else if (value instanceof String) {
            position++;
            return (String) value;
        } 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 14 with MessageNotReadableException

use of javax.jms.MessageNotReadableException in project rabbitmq-jms-client by rabbitmq.

the class RMQBytesMessage method readShort.

/**
 * {@inheritDoc}
 */
@Override
public short readShort() throws JMSException {
    if (!this.reading)
        throw new MessageNotReadableException(NOT_READABLE);
    if (this.pos + Bits.NUM_BYTES_IN_SHORT > this.buf.length)
        throw new MessageEOFException(MSG_EOF);
    short s = Bits.getShort(this.buf, this.pos);
    this.pos += Bits.NUM_BYTES_IN_SHORT;
    return s;
}
Also used : MessageEOFException(javax.jms.MessageEOFException) MessageNotReadableException(javax.jms.MessageNotReadableException)

Example 15 with MessageNotReadableException

use of javax.jms.MessageNotReadableException in project rabbitmq-jms-client by rabbitmq.

the class RMQBytesMessage method readUnsignedShort.

/**
 * {@inheritDoc}
 */
@Override
public int readUnsignedShort() throws JMSException {
    if (!this.reading)
        throw new MessageNotReadableException(NOT_READABLE);
    if (this.pos + Bits.NUM_BYTES_IN_SHORT > this.buf.length)
        throw new MessageEOFException(MSG_EOF);
    short s = Bits.getShort(this.buf, this.pos);
    this.pos += Bits.NUM_BYTES_IN_SHORT;
    return ((int) s) & 0xFFFF;
}
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