Example usage for org.springframework.boot.devtools.tunnel.payload HttpTunnelPayload HttpTunnelPayload

List of usage examples for org.springframework.boot.devtools.tunnel.payload HttpTunnelPayload HttpTunnelPayload

Introduction

In this page you can find the example usage for org.springframework.boot.devtools.tunnel.payload HttpTunnelPayload HttpTunnelPayload.

Prototype

public HttpTunnelPayload(long sequence, ByteBuffer data) 

Source Link

Document

Create a new HttpTunnelPayload instance.

Usage

From source file:org.springframework.boot.devtools.tunnel.payload.HttpTunnelPayload.java

/**
 * Return the {@link HttpTunnelPayload} for the given message or {@code null} if there
 * is no payload.//from w  ww.j  ava  2 s  .c  o m
 * @param message the HTTP message
 * @return the payload or {@code null}
 * @throws IOException in case of I/O errors
 */
public static HttpTunnelPayload get(HttpInputMessage message) throws IOException {
    long length = message.getHeaders().getContentLength();
    if (length <= 0) {
        return null;
    }
    String seqHeader = message.getHeaders().getFirst(SEQ_HEADER);
    Assert.state(StringUtils.hasLength(seqHeader), "Missing sequence header");
    ReadableByteChannel body = Channels.newChannel(message.getBody());
    ByteBuffer payload = ByteBuffer.allocate((int) length);
    while (payload.hasRemaining()) {
        body.read(payload);
    }
    body.close();
    payload.flip();
    return new HttpTunnelPayload(Long.valueOf(seqHeader), payload);
}