 |
Return to article.
Listing 4: Parallel transfer
/**
* Transfer a file in parallel. Requires transfer type IMAGE & transfer mode EBLOCK
* Opens 2 parallel trasfer streams to the same remote file
*/
public void parallelDownload(String remoteFile, String localFile) {
try {
// check if remote file exists, if not an exeception will be thrown...
if ( client.exists(remoteFile) ) {
// transfer type must be IMAGE for parallel...
client.setType(GridFTPSession.TYPE_IMAGE);
/** extended mode is required by paralle transfers **/
client.setMode(GridFTPSession.MODE_EBLOCK);
/** required to transfer multiple files **/
client.setLocalPassive();
client.setActive();
/** set parallelism **/
// Number of parallel stremas to be opened
client.setOptions(new RetrieveOptions(2));
// get file, use the DataSink interface to write incoming data
// Implement it to provide your own ways of storing data.
// It must be thread safe; in parallel transfer mode several streams may attempt to write.
DataSink sink = new FileRandomIO(new RandomAccessFile(localFile,"rw"));
long size = client.getSize(remoteFile);
client.extendedGet(remoteFile, size, sink, null);
// transfer ok
logger.info("Successfully transfered: " + remoteFile + " to " + localFile + " size: " + size);
}
else {
System.err.println(remoteFile + " doesn't exist");
}
}
catch (Exception e) {
e.printStackTrace();
}
}
|
Return to article.
|  |
|