Example usage for org.springframework.messaging.simp.stomp StompHeaderAccessor getContentLength

List of usage examples for org.springframework.messaging.simp.stomp StompHeaderAccessor getContentLength

Introduction

In this page you can find the example usage for org.springframework.messaging.simp.stomp StompHeaderAccessor getContentLength.

Prototype

@Nullable
    public Integer getContentLength() 

Source Link

Usage

From source file:org.springframework.messaging.simp.stomp.StompDecoder.java

@Nullable
private byte[] readPayload(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor) {
    Integer contentLength;/*  w  w  w. ja  v a2s  .  co m*/
    try {
        contentLength = headerAccessor.getContentLength();
    } catch (NumberFormatException ex) {
        if (logger.isWarnEnabled()) {
            logger.warn("Ignoring invalid content-length: '" + headerAccessor);
        }
        contentLength = null;
    }

    if (contentLength != null && contentLength >= 0) {
        if (byteBuffer.remaining() > contentLength) {
            byte[] payload = new byte[contentLength];
            byteBuffer.get(payload);
            if (byteBuffer.get() != 0) {
                throw new StompConversionException("Frame must be terminated with a null octet");
            }
            return payload;
        } else {
            return null;
        }
    } else {
        ByteArrayOutputStream payload = new ByteArrayOutputStream(256);
        while (byteBuffer.remaining() > 0) {
            byte b = byteBuffer.get();
            if (b == 0) {
                return payload.toByteArray();
            } else {
                payload.write(b);
            }
        }
    }
    return null;
}