@SuppressWarnings("OctalInteger")
  private static int toMode(Set<PosixFilePermission> permissions) {
    int result = 0;
    for (PosixFilePermission permission : permissions) {
      checkNotNull(permission);
      switch (permission) {
        case OWNER_READ:
          result |= 0400; // note: octal numbers
          break;
        case OWNER_WRITE:
          result |= 0200;
          break;
        case OWNER_EXECUTE:
          result |= 0100;
          break;
        case GROUP_READ:
          result |= 0040;
          break;
        case GROUP_WRITE:
          result |= 0020;
          break;
        case GROUP_EXECUTE:
          result |= 0010;
          break;
        case OTHERS_READ:
          result |= 0004;
          break;
        case OTHERS_WRITE:
          result |= 0002;
          break;
        case OTHERS_EXECUTE:
          result |= 0001;
          break;
        default:
          throw new AssertionError(); // no other possible values
      }
    }
    return result;
  }
Returns an ID that is guaranteed to be the same for any invocation with equal objects.
jimfs/src/main/java/com/google/common/jimfs/UnixAttributeProvider.java