@Override
    public void completed(Integer result, Entry<ByteBuffer, ByteBuf> attachment) {
        assert subscription != null;
        eventExecutor.execute(() -> {
            assert subscription != null;
            final ByteBuf byteBuf = attachment.getValue();
            if (result > -1) {
                position += result;
                final ByteBuffer byteBuffer = attachment.getKey();
                if (byteBuffer.hasRemaining()) {
                    try {
                        assert fileChannel != null;
                        fileChannel.write(byteBuffer, position, attachment, this);
                    } catch (Throwable ex) {
                        byteBuf.release();
                        maybeCloseFileChannel(ex, false);
                    }
                } else {
                    byteBuf.release();
                    writing = false;

                    if (closing) {
                        maybeCloseFileChannel(null, false);
                    } else {
                        subscription.request(1);
                    }
                }
            } else {
                byteBuf.release();
                subscription.cancel();
                final IOException cause = new IOException(
                        "Unexpected exception while writing data to '" + path + "'. result: " + result);
                maybeCloseFileChannel(cause, false);
            }
        });
    }
Asynchronously writes a {@code StreamMessage<HttpMessage>} to a {@link File}.
core/src/main/java/com/linecorp/armeria/common/stream/AsyncFileWriter.java