Enum Class OverwritePolicy

java.lang.Object
java.lang.Enum<OverwritePolicy>
co.ankatech.ankasecure.sdk.model.OverwritePolicy
All Implemented Interfaces:
Serializable, Comparable<OverwritePolicy>, Constable

public enum OverwritePolicy extends Enum<OverwritePolicy>
Governs how a file-output operation promotes its result onto an already-existing destination (PRD §64).

Every SDK file-output operation — streaming and compact — quarantines its result to a sidecar (<destination>.part) and promotes it to the final path with an atomic rename. This policy selects the rename semantics:

  • FAIL_IF_EXISTS — the default. The sidecar is promoted with a plain same-directory rename (no REPLACE_EXISTING; deliberately NOT ATOMIC_MOVE, because an atomic rename silently replaces an existing target on both Windows and POSIX). If a file already exists at the destination the promotion fails, the sidecar is deleted, and a typed DestinationExistsException is thrown — the pre-existing destination is left byte-for-byte untouched. The rename itself is the TOCTOU race guard: a destination that appears between preflight and promotion is never clobbered.
  • OVERWRITE — opt-in. The sidecar is promoted with ATOMIC_MOVE + REPLACE_EXISTING, atomically replacing any existing destination. On a filesystem that does not support an atomic replacing move (some Windows configurations raise AtomicMoveNotSupportedException) the SDK falls back to deleting the destination and then atomically renaming the sidecar onto it, leaving a minimal, documented non-atomic window.

The policy is selected on an AuthenticatedSdk instance via the immutable withers withOverwritePolicy(OverwritePolicy) / withOverwrite(), each of which returns a new instance sharing the same JWT and HTTP client (no re-authentication).

Since:
3.0.0
Author:
ANKATech Solutions Inc.
  • Enum Constant Details

    • FAIL_IF_EXISTS

      public static final OverwritePolicy FAIL_IF_EXISTS
      Default: refuse to clobber an existing destination (atomic-rename is the TOCTOU guard).
    • OVERWRITE

      public static final OverwritePolicy OVERWRITE
      Opt-in: atomically replace an existing destination (REPLACE_EXISTING, Windows fallback).
  • Method Details

    • values

      public static OverwritePolicy[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static OverwritePolicy valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null