Search in sources :

Example 91 with SessionOutputBuffer

use of org.apache.hc.core5.http.io.SessionOutputBuffer in project httpcomponents-core by apache.

the class AbstractMessageWriter method write.

@Override
public void write(final T message, final SessionOutputBuffer sessionBuffer) throws IOException, HttpException {
    Args.notNull(message, "HTTP message");
    Args.notNull(sessionBuffer, "Session output buffer");
    writeHeadLine(message, this.lineBuf);
    sessionBuffer.writeLine(this.lineBuf);
    for (final Iterator<Header> it = message.headerIterator(); it.hasNext(); ) {
        final Header header = it.next();
        if (header instanceof FormattedHeader) {
            final CharArrayBuffer buffer = ((FormattedHeader) header).getBuffer();
            sessionBuffer.writeLine(buffer);
        } else {
            this.lineBuf.clear();
            this.lineFormatter.formatHeader(this.lineBuf, header);
            sessionBuffer.writeLine(this.lineBuf);
        }
    }
    this.lineBuf.clear();
    sessionBuffer.writeLine(this.lineBuf);
}
Also used : FormattedHeader(org.apache.hc.core5.http.FormattedHeader) Header(org.apache.hc.core5.http.Header) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) FormattedHeader(org.apache.hc.core5.http.FormattedHeader)

Aggregations

Test (org.junit.jupiter.api.Test)88 SessionOutputBuffer (org.apache.hc.core5.http.nio.SessionOutputBuffer)63 BasicHttpTransportMetrics (org.apache.hc.core5.http.impl.BasicHttpTransportMetrics)54 WritableByteChannelMock (org.apache.hc.core5.http.WritableByteChannelMock)52 ByteArrayOutputStream (java.io.ByteArrayOutputStream)34 CharArrayBuffer (org.apache.hc.core5.util.CharArrayBuffer)30 SessionOutputBuffer (org.apache.hc.core5.http.io.SessionOutputBuffer)26 RandomAccessFile (java.io.RandomAccessFile)11 FileChannel (java.nio.channels.FileChannel)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 SessionInputBuffer (org.apache.hc.core5.http.io.SessionInputBuffer)10 OutputStream (java.io.OutputStream)9 WritableByteChannel (java.nio.channels.WritableByteChannel)9 ByteBuffer (java.nio.ByteBuffer)6 CharsetEncoder (java.nio.charset.CharsetEncoder)6 ReadableByteChannel (java.nio.channels.ReadableByteChannel)5 SessionInputBuffer (org.apache.hc.core5.http.nio.SessionInputBuffer)4 Header (org.apache.hc.core5.http.Header)3 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1