private static int remainingBytes(Object buf) {
    if (buf instanceof ByteBuffer) {
      return ((ByteBuffer) buf).remaining();
    } else {
      return ((ByteBuf) buf).readableBytes();
    }
  }
Return the remaining bytes from object buf. When buf is a {@link ByteBuffer}, then call {@link ByteBuffer#remaining()}.
When buf is a {@link ByteBuf}, then call {@link ByteBuf#readableBytes()};
@param buf The buffer.
@return The remaining bytes.
ambry-commons/src/test/java/com/github/ambry/commons/RetainingAsyncWritableChannelTest.java