code: public static boolean isValidType(FileUpload fileUpload, String fileName, InputStream inputStream) {
          try {
              boolean validType = isValidFileName(fileUpload, fileName) && isValidFileContent(fileUpload, fileName, inputStream);
              if (validType) {
                  if (LOGGER.isLoggable(Level.FINE)) {
                      LOGGER.fine(String.format("The uploaded file %s meets the filename and content type specifications", fileName));
                  }
              }
              return validType;
          }
          catch (IOException | ScriptException ex) {
              if (LOGGER.isLoggable(Level.WARNING)) {
                  LOGGER.log(Level.WARNING, String.format("The type of the uploaded file %s could not be validated", fileName), ex);
              }
              return false;
          }
      }
docs: Check if an uploaded file meets all specifications regarding its filename and content type. It evaluates {@link FileUpload#getAllowTypes}
  as well as {@link FileUpload#getAccept} and uses the installed {@link java.nio.file.spi.FileTypeDetector} implementation.
  For most reliable content type checking it's recommended to plug in Apache Tika as an implementation.
  @param fileUpload the fileUpload component
  @param fileName the name of the uploaded file
  @param inputStream the input stream to receive the file's content from
  @return <code>true</code>, if all validations regarding filename and content type passed, <code>false</code> else