@Override
  public void write(byte[] b, int off, int len) throws IOException {
    int currentOffset = off;
    int bytesRemaining = len;

    while (bytesRemaining + buf.readableBytes() > bufSize) {
      int iterationLen = bufSize - buf.readableBytes();
      writeInternal(b, currentOffset, iterationLen);
      currentOffset += iterationLen;
      bytesRemaining -= iterationLen;
    }

    if (bytesRemaining > 0) {
      writeInternal(b, currentOffset, bytesRemaining);
    }
  }
OutputStream to write to the Netty Channel
ql/src/java/org/apache/hadoop/hive/llap/ChannelOutputStream.java