public void sendRequestEntity()

in httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java [201:291]


    public void sendRequestEntity(final ClassicHttpRequest request) throws HttpException, IOException {
        Args.notNull(request, "HTTP request");
        final SocketHolder socketHolder = ensureOpen();
        final HttpEntity entity = request.getEntity();
        if (entity == null) {
            return;
        }
        final long len = this.outgoingContentStrategy.determineLength(request);
        if (len == ContentLengthStrategy.UNDEFINED) {
            throw new LengthRequiredException();
        }
        try (final OutputStream outStream = createContentOutputStream(
                len, this.outbuffer, new OutputStream() {

                    final OutputStream socketOutputStream = socketHolder.getOutputStream();
                    final InputStream socketInputStream = socketHolder.getInputStream();
                    final SSLSocket sslSocket = socketHolder.getSSLSocket();

                    long totalBytes;

                    void checkTLS(final SSLSocket sslSocket) throws IOException {
                        if (sslSocket.isInputShutdown()) {
                            throw new ConnectionClosedException();
                        }
                    }

                    void checkForEarlyResponse(final long totalBytesSent, final int nextWriteSize) throws IOException {
                        if (responseOutOfOrderStrategy.isEarlyResponseDetected(
                                request,
                                DefaultBHttpClientConnection.this,
                                socketInputStream,
                                totalBytesSent,
                                nextWriteSize)) {
                            throw new ResponseOutOfOrderException();
                        }
                    }

                    @Override
                    public void write(final byte[] b) throws IOException {
                        if (sslSocket != null) {
                            checkTLS(sslSocket);
                        }
                        if (responseOutOfOrderStrategy != null) {
                            checkForEarlyResponse(totalBytes, b.length);
                        }
                        totalBytes += b.length;
                        socketOutputStream.write(b);
                    }

                    @Override
                    public void write(final byte[] b, final int off, final int len) throws IOException {
                        if (sslSocket != null) {
                            checkTLS(sslSocket);
                        }
                        if (responseOutOfOrderStrategy != null) {
                            checkForEarlyResponse(totalBytes, len);
                        }
                        totalBytes += len;
                        socketOutputStream.write(b, off, len);
                    }

                    @Override
                    public void write(final int b) throws IOException {
                        if (sslSocket != null) {
                            checkTLS(sslSocket);
                        }
                        if (responseOutOfOrderStrategy != null) {
                            checkForEarlyResponse(totalBytes, 1);
                        }
                        totalBytes++;
                        socketOutputStream.write(b);
                    }

                    @Override
                    public void flush() throws IOException {
                        socketOutputStream.flush();
                    }

                    @Override
                    public void close() throws IOException {
                        socketOutputStream.close();
                    }

                }, entity.getTrailers())) {
            entity.writeTo(outStream);
        } catch (final ResponseOutOfOrderException ex) {
            if (len > 0) {
                this.consistent = false;
            }
        }
    }