code: public static void matchesFilePermissions(String filename,
      PosixFilePermission p) throws IOException {
  
      filenameSanityChecks(filename);
  
      if (p == null)
        throw new NullPointerException("null permission passed as argument");
  
      File f = new File(filename);
  
      // Don't get fooled by symlinks...
      String canonicalPath = f.getCanonicalPath();
  
      String filePerms = getFilePermissions(canonicalPath);
  
      if (!filePerms.startsWith(p.statForm))
        throw new FilePermissionError("Wrong file permissions on file "
          + filename + ". Required permissions are: " + p.chmodForm());
  
    }
docs: Checks that a given file has the appropriate unix permissions. This naive
  implementation just fetches the output of ls -al on a given file and
  matches the resulting string with the permissionString passed as argument.
  
  So the permissionString must be something like:
  
  <pre>
  -rw-------
  </pre>
  
  @param filename
  the filename to be checked
  @param p
  the permission string that must be matched
  @throws IOException
  if an error occurs checking file attributes
  @throws FilePermissionError
  if file permissions are not as requested