public static Set<PosixFilePermission> toPosixPermissions(int mode) {
    Set<PosixFilePermission> permissions = new HashSet<>();
    if ((mode & 0b001_000) == 0b001_000) {
      permissions.add(PosixFilePermission.GROUP_EXECUTE);
    }
    if ((mode & 0b100_000) == 0b100_000) {
      permissions.add(PosixFilePermission.GROUP_READ);
    }
    if ((mode & 0b010_000) == 0b010_000) {
      permissions.add(PosixFilePermission.GROUP_WRITE);
    }

    if ((mode & 0b001) == 0b001) {
      permissions.add(PosixFilePermission.OTHERS_EXECUTE);
    }
    if ((mode & 0b100) == 0b100) {
      permissions.add(PosixFilePermission.OTHERS_READ);
    }
    if ((mode & 0b010) == 0b010) {
      permissions.add(PosixFilePermission.OTHERS_WRITE);
    }

    if ((mode & 0b001_000_000) == 0b001_000_000) {
      permissions.add(PosixFilePermission.OWNER_EXECUTE);
    }
    if ((mode & 0b100_000_000) == 0b100_000_000) {
      permissions.add(PosixFilePermission.OWNER_READ);
    }
    if ((mode & 0b010_000_000) == 0b010_000_000) {
      permissions.add(PosixFilePermission.OWNER_WRITE);
    }

    return permissions;
  }