@Override
  public void close() throws IOException {
    if (closed) {
      throw new IOException("Already closed: " + id);
    }

    try {
      flush();
    } catch (IOException err) {
      LOG.error("Error flushing stream before close on " + id, err);
    }

    closed = true;

    // Wait for all writes to finish before we actually close.
    takeWriteResources(maxPendingWrites);

    try {
      chc.close().addListener(closeListener);
    } finally {
      buf.release();
      buf = null;
      chc = null;
      closed = true;
    }
  }
OutputStream to write to the Netty Channel
ql/src/java/org/apache/hadoop/hive/llap/ChannelOutputStream.java