Class WriteMode

java.lang.Object
com.dropbox.core.v2.files.WriteMode

public final class WriteMode extends Object
Your intent when writing a file to some path. This is used to determine what constitutes a conflict and what the autorename strategy is. In some situations, the conflict behavior is identical: (a) If the target path doesn't refer to anything, the file is always written; no conflict. (b) If the target path refers to a folder, it's always a conflict. (c) If the target path refers to a file with identical contents, nothing gets written; no conflict. The conflict checking differs in the case where there's a file at the target path with contents different from the contents you're trying to write.

This class is a tagged union. Tagged unions instances are always associated to a specific tag. This means only one of the isAbc() methods will return true. You can use tag() to determine the tag associated with this instance.

  • Field Details

    • ADD

      public static final WriteMode ADD
      Do not overwrite an existing file if there is a conflict. The autorename strategy is to append a number to the file name. For example, "document.txt" might become "document (2).txt".
    • OVERWRITE

      public static final WriteMode OVERWRITE
      Always overwrite the existing file. The autorename strategy is the same as it is for ADD.
  • Method Details

    • tag

      public WriteMode.Tag tag()
      Returns the tag for this instance.

      This class is a tagged union. Tagged unions instances are always associated to a specific tag. This means only one of the isXyz() methods will return true. Callers are recommended to use the tag value in a switch statement to properly handle the different values for this WriteMode.

      Returns:
      the tag for this instance.
    • isAdd

      public boolean isAdd()
      Returns true if this instance has the tag WriteMode.Tag.ADD, false otherwise.
      Returns:
      true if this instance is tagged as WriteMode.Tag.ADD, false otherwise.
    • isOverwrite

      public boolean isOverwrite()
      Returns true if this instance has the tag WriteMode.Tag.OVERWRITE, false otherwise.
      Returns:
      true if this instance is tagged as WriteMode.Tag.OVERWRITE, false otherwise.
    • isUpdate

      public boolean isUpdate()
      Returns true if this instance has the tag WriteMode.Tag.UPDATE, false otherwise.
      Returns:
      true if this instance is tagged as WriteMode.Tag.UPDATE, false otherwise.
    • update

      public static WriteMode update(String value)
      Returns an instance of WriteMode that has its tag set to WriteMode.Tag.UPDATE.

      Overwrite if the given "rev" matches the existing file's "rev". The supplied value should be the latest known "rev" of the file, for example, from FileMetadata, from when the file was last downloaded by the app. This will cause the file on the Dropbox servers to be overwritten if the given "rev" matches the existing file's current "rev" on the Dropbox servers. The autorename strategy is to append the string "conflicted copy" to the file name. For example, "document.txt" might become "document (conflicted copy).txt" or "document (Panda's conflicted copy).txt".

      Parameters:
      value - value to assign to this instance.
      Returns:
      Instance of WriteMode with its tag set to WriteMode.Tag.UPDATE.
      Throws:
      IllegalArgumentException - if value is shorter than 9, does not match pattern "[0-9a-f]+", or is null.
    • getUpdateValue

      public String getUpdateValue()
      Overwrite if the given "rev" matches the existing file's "rev". The supplied value should be the latest known "rev" of the file, for example, from FileMetadata, from when the file was last downloaded by the app. This will cause the file on the Dropbox servers to be overwritten if the given "rev" matches the existing file's current "rev" on the Dropbox servers. The autorename strategy is to append the string "conflicted copy" to the file name. For example, "document.txt" might become "document (conflicted copy).txt" or "document (Panda's conflicted copy).txt".

      This instance must be tagged as WriteMode.Tag.UPDATE.

      Returns:
      The String value associated with this instance if isUpdate() is true.
      Throws:
      IllegalStateException - If isUpdate() is false.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toStringMultiline

      public String toStringMultiline()
      Returns a String representation of this object formatted for easier readability.

      The returned String may contain newlines.

      Returns:
      Formatted, multiline String representation of this object