public int write()

in httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedEncoder.java [97:142]


    public int write(final ByteBuffer src) throws IOException {
        if (src == null) {
            return 0;
        }
        assertNotCompleted();

        int total = 0;
        while (src.hasRemaining() && this.remaining > 0) {
            if (this.buffer.hasData() || this.fragHint > 0) {
                final int chunk = nextChunk(src);
                if (chunk <= this.fragHint) {
                    final int capacity = this.fragHint - this.buffer.length();
                    if (capacity > 0) {
                        final int limit = Math.min(capacity, chunk);
                        final int bytesWritten = writeToBuffer(src, limit);
                        this.remaining -= bytesWritten;
                        total += bytesWritten;
                    }
                }
            }
            if (this.buffer.hasData()) {
                final int chunk = nextChunk(src);
                if (this.buffer.length() >= this.fragHint || chunk > 0) {
                    final int bytesWritten = flushToChannel();
                    if (bytesWritten == 0) {
                        break;
                    }
                }
            }
            if (!this.buffer.hasData()) {
                final int chunk = nextChunk(src);
                if (chunk > this.fragHint) {
                    final int bytesWritten = writeToChannel(src, chunk);
                    this.remaining -= bytesWritten;
                    total += bytesWritten;
                    if (bytesWritten == 0) {
                        break;
                    }
                }
            }
        }
        if (this.remaining <= 0) {
            super.complete(null);
        }
        return total;
    }