Class WriteMode


  • public final class WriteMode
    extends java.lang.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 Detail

      • 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 Detail

      • 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.
      • 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​(java.lang.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:
        java.lang.IllegalArgumentException - if value is shorter than 9, does not match pattern "[0-9a-f]+", or is null.
      • getUpdateValue

        public java.lang.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:
        java.lang.IllegalStateException - If isUpdate() is false.
      • hashCode

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

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

        public java.lang.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