Package io.milton.zsync
Class UploadReader
java.lang.Object
io.milton.zsync.UploadReader
An object that performs the server side operations needed to assemble the
file from a ZSync PUT.
These operations consist of copying byte ranges into the new file. The
moveBlocks(byte[], java.util.List<io.milton.zsync.RelocateRange>, int, byte[]) method copies ranges from the previous file according to
a list of RelocateRanges, while the sendRanges(byte[], java.util.List<io.milton.http.Range>, byte[]) method copies the new
data received in the upload. Both of these methods are overloaded with
versions that accept File rather than byte[] arguments for dealing with large
files that should not be loaded into memory all at once.
To assemble the file from a ZSync upload, the server should construct an
UploadReader, passing to the constructor the file to be updated and an
InputStream containing the upload data. It should then invoke the
assemble() method, which will return a temporary file that was
created.- Author:
- Nick
-
Constructor Summary
ConstructorsConstructorDescriptionUploadReader(File serverFile, InputStream uploadIn) Constructor that parses the InputStream into an Upload object and initializes a temporary file that will contain the assembled upload -
Method Summary
Modifier and TypeMethodDescriptionassemble()Invokes the methods to put together the uploaded file.Returns the expected SHA1 checksum String received in the uploadstatic voidmoveBlocks(byte[] in, List<RelocateRange> rlist, int blockSize, byte[] out) Copies blocks of data from the in array to the out array.static voidmoveBlocks(File inFile, Enumeration<RelocateRange> relocRanges, int blocksize, File outFile) Copies blocks of data from the input File to the output File.static voidsendRanges(byte[] in, List<Range> ranges, byte[] out) Copies bytes from the in array into Ranges of the out array.static voidsendRanges(Enumeration<ByteRange> byteRanges, File outFile) Inserts the data from each DataRange into the output File, at the appropriate offset
-
Constructor Details
-
UploadReader
Constructor that parses the InputStream into an Upload object and initializes a temporary file that will contain the assembled upload- Parameters:
serverFile- The server file to be updateduploadIn- A stream containing the ZSync PUT data- Throws:
IOException
-
-
Method Details
-
moveBlocks
Copies blocks of data from the in array to the out array.- Parameters:
in- The byte array containing the server's file being replacedrlist- The List of RelocateRanges received from the uploadblockSize- The block size used in rlistout- The byte array of the file being assembled
-
moveBlocks
public static void moveBlocks(File inFile, Enumeration<RelocateRange> relocRanges, int blocksize, File outFile) throws IOException Copies blocks of data from the input File to the output File. For each RelocateRange A-B/C in relocRanges, the block starting at A and ending at B-1 is copied from inFile and written to byte C of outFile.- Parameters:
inFile- The server's File being replacedrelocRanges- The Enumeration of RelocateRanges parsed from the Upload's relocStreamblocksize- The block size used in relocRangesoutFile- The File being assembled- Throws:
IOException
-
sendRanges
Copies bytes from the in array into Ranges of the out array. The in array is expected to contain the queued bytes in the same order as the ranges List.- Parameters:
in- An array containing the queued bytes corresponding to the ranges Listranges- The List of target Rangesout- The byte array for the file being assembled
-
sendRanges
Inserts the data from each DataRange into the output File, at the appropriate offset- Parameters:
byteRanges- The Enumeration of Range/InputStream pairs parsed from the Upload's dataStreamoutFile- The output File being assembled- Throws:
IOException
-
assemble
Invokes the methods to put together the uploaded file.- Returns:
- The assembled File
- Throws:
IOException
-
getChecksum
Returns the expected SHA1 checksum String received in the upload- Returns:
- A SHA1 checksum
-