private void flush0(CompletableFuture<Long> future, ByteArrayOutputStream buffer, boolean sync) {
    try {
      if (buffer.size() > 0) {
        out.write(buffer.getBuffer(), 0, buffer.size());
        if (sync) {
          out.hsync();
        } else {
          out.hflush();
        }
      }
      long pos = out.getPos();
      /**
       * This flush0 method could only be called by single thread, so here we could safely overwrite
       * without any synchronization.
       */
      this.syncedLength = pos;
      future.complete(pos);
    } catch (IOException e) {
      future.completeExceptionally(e);
      return;
    }
  }
An {@link AsyncFSOutput} wraps a {@link FSDataOutputStream}.
hbase-asyncfs/src/main/java/org/apache/hadoop/hbase/io/asyncfs/WrapperAsyncFSOutput.java