Example usage for javax.jms BytesMessage getClass

List of usage examples for javax.jms BytesMessage getClass

Introduction

In this page you can find the example usage for javax.jms BytesMessage getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.apache.axis2.transport.jms.JMSUtils.java

/**
 * Return the body length in bytes for a bytes message
 * @param bMsg the JMS BytesMessage/*  ww w.j  av a  2 s.  c o m*/
 * @return length of body in bytes
 */
public static long getBodyLength(BytesMessage bMsg) {
    try {
        Method mtd = bMsg.getClass().getMethod("getBodyLength", NOARGS);
        if (mtd != null) {
            return (Long) mtd.invoke(bMsg, NOPARMS);
        }
    } catch (Exception e) {
        // JMS 1.0
        if (log.isDebugEnabled()) {
            log.debug("Error trying to determine JMS BytesMessage body length", e);
        }
    }

    // if JMS 1.0
    long length = 0;
    try {
        byte[] buffer = new byte[2048];
        bMsg.reset();
        for (int bytesRead = bMsg.readBytes(buffer); bytesRead != -1; bytesRead = bMsg.readBytes(buffer)) {
            length += bytesRead;
        }
    } catch (JMSException ignore) {
    }
    return length;
}