public class UploadMaker extends Object
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);UploadMakerEx, performs the same functions but may perform
better for certain rare cases.Upload}, {@link UploadReader}, {@link UploadMakerEx}| Modifier and Type | Field and Description |
|---|---|
File |
localCopy
The local file that will replace the server file
|
File |
serversMetafile
The .zsync of the server file to be replaced
|
| Constructor and Description |
|---|
UploadMaker(File sourceFile,
File destMeta)
Constructor that automatically creates and fills in an internal upload
object.
|
| Modifier and Type | Method and Description |
|---|---|
static List<DataRange> |
getDataRanges(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 InputStream |
getDataStream(List<Range> ranges,
File local)
Generates the dataStream portion of an Upload from the local file and a
List of Ranges
|
InputStream |
getInputStream()
Returns the stream of bytes to be used as the body of a ZSync PUT.
|
static InputStream |
getRelocStream(List<RelocateRange> relocList)
Generates the relocStream portion of an Upload from a List of
RelocateRanges.
|
void |
init() |
InputStream |
makeUpload() |
static InputStream |
serversMissingRanges(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 InputStream |
serversRelocationRanges(long[] fileMap,
int blockSize,
long fileLength,
boolean combineRanges)
Returns the assembly instructions needed by the server to relocate the
blocks it already has.
|
public final File localCopy
public final File serversMetafile
public UploadMaker(File sourceFile, File destMeta) throws IOException
sourceFile - The local file to be uploadeddestMeta - The zsync of the server's fileIOExceptionpublic InputStream makeUpload() throws IOException
IOExceptionpublic void init()
throws IOException
IOExceptionpublic static InputStream serversMissingRanges(long[] fileMap, File local, int blockSize) throws IOException
fileMap argument 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 that
fileMap[seq] == off means that block number
seq in the server's file matches the block in the local file
beginning at byte
off. An invalid offset is ignored and should be used to
indicate that the local file contains no match for that block. The
fileMap array can be obtained from the MakeContext
class.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
in fileMapIOExceptionpublic static InputStream serversRelocationRanges(long[] fileMap, int blockSize, long fileLength, boolean combineRanges) throws IOException
combineRanges argument 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.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 RelocateRangeIOExceptionpublic static List<DataRange> getDataRanges(List<Range> ranges, File local) throws IOException
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 uploadedIOExceptionpublic InputStream getInputStream() throws UnsupportedEncodingException, IOException
UnsupportedEncodingExceptionIOExceptionpublic static InputStream getRelocStream(List<RelocateRange> relocList) throws IOException
relocList - The List of RelocateRangesIOExceptionpublic static InputStream getDataStream(List<Range> ranges, File local) throws IOException
ranges - The List of byte rangeslocal - The local file being uploadedIOExceptionCopyright © 2021 McEvoy Software Ltd. All rights reserved.