public static String toBase64(FacesContext context, byte[] bytes, String contentType) {
        String base64 = Base64.getEncoder().withoutPadding().encodeToString(bytes);
        if (contentType == null) {
            // try to guess content type from magic numbers
            if (base64.startsWith("R0lGOD")) {
                contentType = "image/gif";
            }
            else if (base64.startsWith("iVBORw")) {
                contentType = "image/png";
            }
            else if (base64.startsWith("/9j/")) {
                contentType = "image/jpeg";
            }
            else if (base64.startsWith("UklGR")) {
                contentType = "image/webp";
            }
        }
        return "data:" + contentType + ";base64," + base64;
    }
Used to extract resource name (e.g. "#{resource['picture.png'}")
primefaces/src/main/java/org/primefaces/util/ResourceUtils.java