Class RelocateRange

java.lang.Object
io.milton.zsync.RelocateRange

public final class RelocateRange extends Object
An object consisting of a Range and a long offset.

A RelocateRange is an instruction sent as part of a ZSync PUT upload, which informs the server of the new offset of a single range of blocks from the original file. The String format for this object as it appears in the upload is currently "A-B/C", where A-B indicates the block range starting at A and ending at B-1, and C represents the location of this sequence of blocks in the updated (client-side) file.

Author:
Nick
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The String separating the Range from the offset in the String representation of this object.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RelocateRange(Range range, long offset)
    Constructs a RelocateRange from a Range and offset.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the range of blocks to be relocated.
    long
    Returns the byte position to which the Range should be relocated.
    Returns a String representing this object, e.g. "10-20/1234", ready to be inserted into a ZSync PUT upload request.
    parse(String relocString)
    Constructs and returns a RelocateRange object from the input String.
    Returns a String description of this object, not meant to be inserted into a ZSync PUT.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • DIV

      public static final String DIV
      The String separating the Range from the offset in the String representation of this object.
      See Also:
  • Constructor Details

    • RelocateRange

      public RelocateRange(Range range, long offset)
      Constructs a RelocateRange from a Range and offset. The object is immutable; the fields cannot be changed after construction.
      Parameters:
      range - A range of block indices in the remote file
      offset - The new byte position of range
  • Method Details

    • toString

      public String toString()
      Returns a String description of this object, not meant to be inserted into a ZSync PUT. For the proper PUT formatting, use getRelocation()
      Overrides:
      toString in class Object
      Returns:
      A brief description of this object
    • getRelocation

      public String getRelocation()
      Returns a String representing this object, e.g. "10-20/1234", ready to be inserted into a ZSync PUT upload request.
      Returns:
      A String representing this object
    • parse

      public static RelocateRange parse(String relocString) throws ParseException
      Constructs and returns a RelocateRange object from the input String. The String should be in the format A-B/C.

      Note: Leading and trailing whitespaces in the argument are ignored, but there should be no spaces between the non-ws chars.

      Parameters:
      relocString - The String to be parsed
      Returns:
      The RelocateRange object corresponding to relocString
      Throws:
      ParseException - If the format of the input String is incorrect or the numbers cannot be properly parsed
    • getBlockRange

      public Range getBlockRange()
      Returns the range of blocks to be relocated.

      The numbers in the Range are indices of the blocks in the server's copy of the file. The Range consists of the pair (firstBlock, lastBlock + 1).

      Returns:
      A Range object containing the block range
    • getOffset

      public long getOffset()
      Returns the byte position to which the Range should be relocated.
      Returns:
      The new offset of the Range