@SuppressWarnings("unchecked") // only cast after checking each element's type
  private static ImmutableSet<PosixFilePermission> toPermissions(Set<?> set) {
    ImmutableSet<?> copy = ImmutableSet.copyOf(set);
    for (Object obj : copy) {
      if (!(obj instanceof PosixFilePermission)) {
        throw new IllegalArgumentException(
            "invalid element for attribute 'posix:permissions': "
                + "should be Set<PosixFilePermission>, found element of type "
                + obj.getClass());
      }
    }

    return Sets.immutableEnumSet((ImmutableSet<PosixFilePermission>) copy);
  }
Attribute provider that provides the {@link PosixFileAttributeView} ("posix") and allows reading
of {@link PosixFileAttributes}.

@author Colin Decker
jimfs/src/main/java/com/google/common/jimfs/PosixAttributeProvider.java