code: protected byte[] getBinaryData(Resource resource, @SuppressWarnings("unused") SlingHttpServletRequest request) throws IOException {
      InputStream is = resource.adaptTo(InputStream.class);
      if (is == null) {
        return null;
      }
      try {
        return IOUtils.toByteArray(is);
      }
      finally {
        is.close();
      }
    }
docs: Get binary data from the referenced nt:file or nt:resourcer resource.
  @param resource Resource
  @return Binary data or null if not binary data found
  @throws IOException