class RestUtils {

    public static Response createPaginatedResponseWithJson(UriInfo uriInfo, JSONArray items, int totalSize, int limit,
                                                           int offset) {
        long start = System.currentTimeMillis();
        try {
            LinksUtils.validateParams(limit, offset);
            Links links = LinksUtils.buildLinks(uriInfo, items.size(), totalSize, limit, offset);
            Response.ResponseBuilder response = Response.ok(items).header("X-Total-Count", totalSize);
            if (links.getNext() != null) {
                response = response.link(links.getBase() + links.getNext(), "next");
            }
            if (links.getPrev() != null) {
                response = response.link(links.getBase() + links.getPrev(), "prev");
            }
            return response.build();
        } finally {
            LOG.trace("createPaginatedResponseWithJson took {}ms", System.currentTimeMillis() - start);
        }
    }

}