Example usage for org.springframework.core.io.buffer DataBuffer write

List of usage examples for org.springframework.core.io.buffer DataBuffer write

Introduction

In this page you can find the example usage for org.springframework.core.io.buffer DataBuffer write.

Prototype

DataBuffer write(byte[] source, int offset, int length);

Source Link

Document

Write at most length bytes of the given source into this buffer, starting at the current writing position of this buffer.

Usage

From source file:org.springframework.http.server.reactive.ServletServerHttpRequest.java

/**
 * Read from the request body InputStream and return a DataBuffer.
 * Invoked only when {@link ServletInputStream#isReady()} returns "true".
 *//*  ww  w.  ja v a 2  s  .  c o m*/
@Nullable
protected DataBuffer readFromInputStream() throws IOException {
    int read = this.request.getInputStream().read(this.buffer);
    if (logger.isTraceEnabled()) {
        logger.trace("InputStream read returned " + read + (read != -1 ? " bytes" : ""));
    }

    if (read > 0) {
        DataBuffer dataBuffer = this.bufferFactory.allocateBuffer(read);
        dataBuffer.write(this.buffer, 0, read);
        return dataBuffer;
    }

    return null;
}