Class PosixPermissions.PosixPermissionsBuilder

java.lang.Object
com.sshtools.common.sftp.PosixPermissions.PosixPermissionsBuilder
Enclosing class:
PosixPermissions

public static final class PosixPermissions.PosixPermissionsBuilder extends Object
A builder for PosixPermissions.
  • Method Details

    • create

      Returns:
      builder
    • build

      public PosixPermissions build()
      Build a new PosixPermissions set.
      Returns:
      permissions
    • fromAllPermissions

      public PosixPermissions.PosixPermissionsBuilder fromAllPermissions()
      Add all permissions for everyone.
      Returns:
      this for chaining
    • fromBitmask

      public PosixPermissions.PosixPermissionsBuilder fromBitmask(long mode)
      Set the mode using a either a raw int or a raw long. Only the first 32 bits of the value will be used.

      Any existing value already built will be entirely replaced with this new value.

      Parameters:
      raw - mode value
      Returns:
      this for chaining
    • fromBitmask

      public PosixPermissions.PosixPermissionsBuilder fromBitmask(com.sshtools.common.util.UnsignedInteger32 mode)
      Set the mode using a a raw unsigned 32 bit value.

      Any existing value already built will be entirely replaced with this new value.

      Parameters:
      raw - mode value
      Returns:
      this for chaining
    • fromFileModeString

      public PosixPermissions.PosixPermissionsBuilder fromFileModeString(String fileModes)
      Set the mode using a full (9 character) file mode string. The first 3 characters are for the user, the second 3 are for group and the final 3 are for other users. The correlating output is PosixPermissions.asFileModesString().

      Any existing value already built will be entirely replaced with this new value.

      Parameters:
      file - mode string
      Returns:
      this for chaining
    • fromLaxFileModeString

      public PosixPermissions.PosixPermissionsBuilder fromLaxFileModeString(String fileModes)
      Set the mode using a file mode string. The string can be any length up to 9 characters, with any length less than this padding the string with '-' until it is 9 characters in length. The first 3 characters are for the user, the second 3 are for group and the final 3 are for other users. The correlating output is PosixPermissions.asFileModesString().

      Any existing value already built will be entirely replaced with this new value.

      Parameters:
      file - mode string
      Returns:
      this for chaining
    • fromMaskString

      public PosixPermissions.PosixPermissionsBuilder fromMaskString(String maskString)
      Set the mode using a UNIX style mask octal string, for example '0644'. This should be in the same format as that output by PosixPermissions.asMaskString().

      Any existing value already built will be entirely replaced with this new value.

      Parameters:
      maskString - octal mask string
      Returns:
      this for chaining
    • fromNoPermissions

      public PosixPermissions.PosixPermissionsBuilder fromNoPermissions()
      Removes all permission from the set to be built.
      Returns:
      this for chaining
    • fromPermissions

      public PosixPermissions.PosixPermissionsBuilder fromPermissions(PosixFilePermission... permissions)
      Set the mode using an array of PosixFilePermission.

      Any existing value already built will be entirely replaced with this new value.

      Parameters:
      permissions - permissions
      Returns:
      this for chaining
    • fromPermissions

      Set the mode using a collection of PosixFilePermission.

      Any existing value already built will be entirely replaced with this new value.

      Parameters:
      permissions - permissions
      Returns:
      this for chaining
    • fromPosixPermissions

      public PosixPermissions.PosixPermissionsBuilder fromPosixPermissions(PosixPermissions permissions)
      Set the mode using an existing PosixPermissions.

      Any existing value already built will be entirely replaced with this new value.

      Parameters:
      permissions - permissions
      Returns:
      this for chaining
    • fromUmaskString

      public PosixPermissions.PosixPermissionsBuilder fromUmaskString(String umask)
      Set the mode using a UNIX style umask, for example '0022' will result in 0022 ^ 0777. This should be in the same format as that output by PosixPermissions#asUmaskString().

      Any existing value already built will be entirely replaced with this new value.

      Parameters:
      umask - octal umask string
      Returns:
      this for chaining
    • withAllExecute

      Adds execute permission to user, group and other.
      Returns:
      this for chaining
    • withAllRead

      Adds read permission to user, group and other.
      Returns:
      this for chaining
    • withAllWrite

      Adds write permission to user, group and other.
      Returns:
      this for chaining
    • withBitmaskFlags

      public PosixPermissions.PosixPermissionsBuilder withBitmaskFlags(long flags)
      Adds a set of modes using bitmask flags via a raw int or a raw long. Only the first 32 bits of the value will be used.
      Parameters:
      bitmask - mask of flags to add
      Returns:
      this for chaining
    • withChmodArgumentString

      public PosixPermissions.PosixPermissionsBuilder withChmodArgumentString(String chmodArgument)
      Set the mode using a format compatible with the UNIX chmod command. It supports either settings, adding or removing permissions from either the user, group or other parts.

      For example, u=rw,g=r,o=r would set read-write on the user, and only read on group and other. Or, u+x,g=,o= would add execute permission for user, and clear group and other of all permissions.

      Note this does not replace all permissions in this builder unless the argment string provided specifies to do so, e.g. u=,g=,o= or u-rwx,g-rwx,o-rwx would remove all permissions.

      You can use an octal mask string with chmod and so that is also possible here.

      Parameters:
      chmodArgument - permissions expressed in format used by chmod UNIX command
      Returns:
      this for chaining
    • withoutBitmaskFlags

      public PosixPermissions.PosixPermissionsBuilder withoutBitmaskFlags(long flags)
      Remove a set of modes using bitmask flags via a raw int or a raw long. Only the first 32 bits of the value will be used.
      Parameters:
      bitmask - mask of flags to remove
      Returns:
      this for chaining
    • withoutExecutePermissions

      public PosixPermissions.PosixPermissionsBuilder withoutExecutePermissions()
      Removes all execute permissions.
      Returns:
      this for chaining
    • withoutGroupOtherPermissions

      public PosixPermissions.PosixPermissionsBuilder withoutGroupOtherPermissions()
      Removes all group and other permissions.
      Returns:
      this for chaining
    • withoutOtherPermissions

      public PosixPermissions.PosixPermissionsBuilder withoutOtherPermissions()
      Removes all other permissions.
      Returns:
      this for chaining
    • withoutPermissions

      Remove a collection of PosixFilePermission from the built set of permissions.
      Parameters:
      permissions - permissions to remove
      Returns:
      this for chaining
    • withoutPermissions

      public PosixPermissions.PosixPermissionsBuilder withoutPermissions(PosixFilePermission... permissions)
      Remove one or more PosixFilePermission from the built set of permissions.
      Parameters:
      permissions - permissions to remove
      Returns:
      this for chaining
    • withoutWritePermissions

      public PosixPermissions.PosixPermissionsBuilder withoutWritePermissions()
      Removes all write permissions.
      Returns:
      this for chaining
    • withPermissions

      Add a collection of PosixFilePermission to the built set of permissions.
      Parameters:
      permissions - permissions
      Returns:
      this for chaining
    • withPermissions

      public PosixPermissions.PosixPermissionsBuilder withPermissions(PosixFilePermission... permissions)
      Add one or more PosixFilePermission to the built set of permissions.
      Parameters:
      permissions - permissions
      Returns:
      this for chaining