try {
File localFile = store.getLocalFile();
if (logger.isDebugEnabled())
logger.debug("[" + uri + "]: Downloading to " + (localFile == null ? "(null)" : localFile.toString()));
HDFSManager.INSTANCE.startServerOperation(uri.toString());
final IFileInfo serverInfo = store.fetchInfo();
if (serverInfo.exists()) {
monitor.beginTask("Downloading " + uri.toString(), (int) serverInfo.getLength());
if (!localFile.exists()) {
localFile.getParentFile().mkdirs();
localFile.createNewFile();
}
InputStream openInputStream = store.openRemoteInputStream(EFS.NONE, new NullProgressMonitor());
FileOutputStream fos = new FileOutputStream(localFile);
try {
if (!monitor.isCanceled()) {
byte[] data = new byte[8 * 1024];
int totalRead = 0;
int read = openInputStream.read(data);
while (read > -1) {
if (monitor.isCanceled())
throw new InterruptedException();
fos.write(data, 0, read);
totalRead += read;
monitor.worked(read);
read = openInputStream.read(data);
if (logger.isDebugEnabled())
logger.debug("Downloaded " + totalRead + " out of " + serverInfo.getLength() + " [" + (((float)totalRead*100.0f) / (float)serverInfo.getLength())
+ "]");
}
}
} catch (IOException e) {
throw e;