Package io.milton.zsync
Class UploadMaker
java.lang.Object
io.milton.zsync.UploadMaker
An object that performs the client-side operations needed to generate ZSync
PUT data.
In order to update a file on a server, the client first needs to download the
appropriate .zsync containing the metadata of the server file. The client
should then instantiate an
InputStream putData = um.getInputStream(); Note: This is one of two classes that can be used to create a ZSync upload. The other class,
UploadMaker, passing to the constructor this .zsync file as well
as the local file to be uploaded. On construction, the
UploadMaker will determine the data ranges and assembly
instructions that need to be sent to the server, and will automatically fill
in an internal
Upload object. The client can then invoke the
getInputStream method, which will return a stream which should
be used as the body of a PUT request.
E.g:
<
code>
UploadMaker um = new UploadMaker(File clientFile, File zsFile);InputStream putData = um.getInputStream(); Note: This is one of two classes that can be used to create a ZSync upload. The other class,
UploadMakerEx, performs the same functions but may perform
better for certain rare cases.- Author:
- Nick
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionUploadMaker(File sourceFile, File destMeta) Constructor that automatically creates and fills in an internal upload object. -
Method Summary
Modifier and TypeMethodDescriptiongetDataRanges(List<Range> ranges, File local) Returns the List of DataRange objects containing the portions of the client file to be uploaded to the server.static InputStreamgetDataStream(List<Range> ranges, File local) Generates the dataStream portion of an Upload from the local file and a List of RangesReturns the stream of bytes to be used as the body of a ZSync PUT.static InputStreamgetRelocStream(List<RelocateRange> relocList) Generates the relocStream portion of an Upload from a List of RelocateRanges.voidinit()static InputStreamserversMissingRanges(long[] fileMap, File local, int blockSize) Determines the byte ranges of new data that need to be sent to the server to update its file.static InputStreamserversRelocationRanges(long[] fileMap, int blockSize, long fileLength, boolean combineRanges) Returns the assembly instructions needed by the server to relocate the blocks it already has.
-
Field Details
-
localCopy
The local file that will replace the server file -
serversMetafile
The .zsync of the server file to be replaced
-
-
Constructor Details
-
UploadMaker
Constructor that automatically creates and fills in an internal upload object.- Parameters:
sourceFile- The local file to be uploadeddestMeta- The zsync of the server's file- Throws:
IOException
-
-
Method Details
-
makeUpload
- Throws:
IOException
-
init
- Throws:
IOException
-
serversMissingRanges
public static InputStream serversMissingRanges(long[] fileMap, File local, int blockSize) throws IOException Determines the byte ranges of new data that need to be sent to the server to update its file. ThefileMapargument should be an array that maps matching blocks from the server's file (the side that sent the metadata) to those in the client file, such thatfileMap[seq] == offmeans that block numberseqin the server's file matches the block in the local file beginning at byteoff. An invalid offset is ignored and should be used to indicate that the local file contains no match for that block. ThefileMaparray can be obtained from the MakeContext class.- Parameters:
fileMap- An array mapping blocks in server file to their offsets in local filefileLength- The length of the local file to be uploadedblockSize- The size of a block. Must correspond to block size used infileMap- Returns:
- The List of byte Ranges that need to be sent
- Throws:
IOException
-
serversRelocationRanges
public static InputStream serversRelocationRanges(long[] fileMap, int blockSize, long fileLength, boolean combineRanges) throws IOException Returns the assembly instructions needed by the server to relocate the blocks it already has. ThecombineRangesargument determines whether contiguous matching blocks should be combined into a single range, e.g. given a blockSize of 100, whether 0-10/500, 10-20/600, 20-30/700 should be combined into the single RelocateRange of 0-30/500.- Parameters:
fileMap- An array mapping blocks in the server file to their matches in the local fileblockSize- The block size used by fileMapfileLength- The length of the local file to be uploadedcombineRanges- Whether consecutive matches should be combined into a single RelocateRange- Returns:
- A list of RelocateRange instructions to be sent to the server
- Throws:
IOException
-
getDataRanges
Returns 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#serversMissingRanges(long[], long, int)local- The client file to be uploaded- Returns:
- The List of DataRange objects containing client file portions to be uploaded
- Throws:
IOException
-
getInputStream
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 once 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
-
getRelocStream
Generates the relocStream portion of an Upload from a List of RelocateRanges.- Parameters:
relocList- The List of RelocateRanges- Returns:
- An InputStream containing the relocStream portion of an Upload
- Throws:
IOException
-
getDataStream
Generates the dataStream portion of an Upload from the local file and a List of Ranges- Parameters:
ranges- The List of byte rangeslocal- The local file being uploaded- Returns:
- The InputStream containing the dataStream portion of an Upload
- Throws:
IOException
-