private ByteBuf getChunkBuf(ChunkData chunkData) {
    ByteBuf chunkBuf = null;
    if (chunkData != null && chunkData.buf != null) {
      chunkBuf = chunkData.buf;
      chunksAwaitingResolution.add(chunkData);
      if (!isOpen()) {
        chunkBuf = null;
        resolveAllRemainingChunks(new ClosedChannelException());
      }
    }
    return chunkBuf;
  }
Gets the {@link ByteBuf} associated with the chunk if there is one. Also updates internal state.
@param chunkData the data associated with the chunk whose buffer needs to be returned.
@return the buffer inside {@code chunkData} if there is one.
ambry-commons/src/main/java/com/github/ambry/commons/ByteBufferAsyncWritableChannel.java