Package io.milton.zsync
Class UploadMakerEx
java.lang.Object
io.milton.zsync.UploadMakerEx
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionUploadMakerEx(File sourceFile, File zsFile) Constructor that initializes an Upload object and invokes methods to parse the zsync file. -
Method Summary
Modifier and TypeMethodDescriptionstatic InputStreamgetDataRanges(List<Range> ranges, File local) Constructs the List of DataRange objects containing the portions of the client file to be uploaded to the server.Generates the upload content to a temp file.Returns the stream of bytes to be used as the body of a ZSync PUT.static InputStreamserversMissingRangesEx(List<OffsetPair> reverseMap, File local, int blockSize) Determines the byte ranges from the client file that need to be uploaded to the server.static InputStreamserversRelocationRangesEx(List<OffsetPair> reverseMap, int blockSize, long fileLength, boolean combineRanges) Determines the instructions needed by the server to relocate blocks of data already contained in its version of the file.
-
Field Details
-
localCopy
The local file that will replace the server file -
serversMetafile
The .zsync of the server file to be replaced
-
-
Constructor Details
-
UploadMakerEx
Constructor that initializes an Upload object and invokes methods to parse the zsync file.- Parameters:
sourceFile- The client file to be uploadedzsFile- 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 MakeContextExlocal- The local file being uploadedblockSize- The block size used in reverseMap- Returns:
- An InputStream containing the dataStream portion of an Upload
- Throws:
IOExceptionUnsupportedEncodingException- 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 MakeContextExblockSize- The block size used to generate reverseMapfileLength- The length of the client file being uploadedcombineRanges- Whether to combine consecutive block matches into a single RelocateRange- Returns:
- The InputStream of RelocateRanges that need to be sent to the server
- Throws:
IOExceptionUnsupportedEncodingException
-
getDataRanges
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
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:
UnsupportedEncodingExceptionIOException
-
getUploadFile
Generates the upload content to a temp file.- Returns:
- Throws:
IOException
-