public static <T> T copyAndClose(T obj) {
        if (obj instanceof HttpData) {
            final HttpData data = (HttpData) obj;
            if (data.isPooled()) {
                try {
                    @SuppressWarnings("unchecked")
                    final T copy = (T) HttpData.wrap(data.array()).withEndOfStream(data.isEndOfStream());
                    return copy;
                } finally {
                    data.close();
                }
            }
        }
        if (obj instanceof WebSocketFrame) {
            final WebSocketFrame frame = (WebSocketFrame) obj;
            if (frame.isPooled()) {
                return copyAndCloseWebSocketFrame(frame);
            }
        }

        return obj;
    }
Creates an unpooled copy of the given {@link HttpData} and closes the given {@link HttpData}.
Returns the given object as is if it's not a pooled {@link HttpData}. This method is useful when
you need to pass your pooled {@link HttpData} instances to the third party who is not capable of
handling pooled {@link HttpData}.

@param obj maybe an {@link HttpData} to copy
core/src/main/java/com/linecorp/armeria/unsafe/PooledObjects.java