Class UploadMakerEx

java.lang.Object
io.milton.zsync.UploadMakerEx

public class UploadMakerEx extends Object
A slight variation of UploadMaker that accommodates updating of potentially redundant files, ie files containing blocks that repeat at multiple offsets.

It is not necessary to use this class rather than UploadMaker. This class simply decreases the amount of data that needs to be transmitted for certain cases of redundant files. The sole difference from UploadMaker is that this class uses methods that expect a reverse block-matching in the form of an array where f[serverIndex] = localOffset (actually implemented as a List of OffsetPairs), whereas UploadMaker expects f[localOffset] = serverIndex.

The main advantage of the reverse mapping is that it allows multiple identical block ranges in the local file to be mapped to a single range in the server file. If a given block occurs more times on the local file than on the server file, the f[serverIndex] array will not identify all of those local occurences, and the unmatched ones will be transmitted needlessly.

Author:
Nick
  • Field Details

    • localCopy

      public final File localCopy
      The local file that will replace the server file
    • serversMetafile

      public final File serversMetafile
      The .zsync of the server file to be replaced
  • Constructor Details

    • UploadMakerEx

      public UploadMakerEx(File sourceFile, File zsFile) throws IOException
      Constructor that initializes an Upload object and invokes methods to parse the zsync file.
      Parameters:
      sourceFile - The client file to be uploaded
      zsFile - The zsync of the server's file
      Throws:
      IOException
  • Method Details

    • serversMissingRangesEx

      public static InputStream serversMissingRangesEx(List<OffsetPair> reverseMap, File local, int blockSize) throws UnsupportedEncodingException, IOException
      Determines the byte ranges from the client file that need to be uploaded to the server.
      Parameters:
      reverseMap - The List of block-matches obtained from MakeContextEx
      local - The local file being uploaded
      blockSize - The block size used in reverseMap
      Returns:
      An InputStream containing the dataStream portion of an Upload
      Throws:
      IOException
      UnsupportedEncodingException
      See Also:
    • serversRelocationRangesEx

      public static InputStream serversRelocationRangesEx(List<OffsetPair> reverseMap, int blockSize, long fileLength, boolean combineRanges) throws UnsupportedEncodingException, IOException
      Determines the instructions needed by the server to relocate blocks of data already contained in its version of the file.
      Parameters:
      reverseMap - The List of block-matches obtained from MakeContextEx
      blockSize - The block size used to generate reverseMap
      fileLength - The length of the client file being uploaded
      combineRanges - Whether to combine consecutive block matches into a single RelocateRange
      Returns:
      The InputStream of RelocateRanges that need to be sent to the server
      Throws:
      IOException
      UnsupportedEncodingException
    • getDataRanges

      public static InputStream getDataRanges(List<Range> ranges, File local) throws IOException
      Constructs the List of DataRange objects containing the portions of the client file to be uploaded to the server. Currently unused.
      Parameters:
      ranges - The List of Ranges from the client file needed by the server, which can be obtained from #serversMissingRangesEx(List, long, int)
      local - The client file to be uploaded
      Returns:
      An InputStream containing the dataStream portion of an Upload
      Throws:
      IOException
    • makeUpload

      public InputStream makeUpload() throws IOException
      Returns the stream of bytes to be used as the body of a ZSync PUT.

      Note: Any temporary files used to store the data for the stream will be deleted after the stream is closed, so a second invocation of this method may not work.

      Returns:
      The InputStream containing the data for a ZSync PUT
      Throws:
      UnsupportedEncodingException
      IOException
    • getUploadFile

      public File getUploadFile() throws IOException
      Generates the upload content to a temp file.
      Returns:
      Throws:
      IOException