final IBookMark bm = (IBookMark) fInput.getMark();
final URI feedLink = bm.getFeedLinkReference().getLink();
try {
final IProtocolHandler handler = Owl.getConnectionService().getHandler(feedLink);
if (handler instanceof org.rssowl.core.internal.connection.DefaultProtocolHandler) {
Job downloadJob = new Job(Messages.FeedView_DOWNLOADING_FEED) {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask(bm.getName(), IProgressMonitor.UNKNOWN);
InputStream in = null;
FileOutputStream out = null;
boolean canceled = false;
Exception error = null;
try {
byte[] buffer = new byte[8192];
in = handler.openStream(feedLink, monitor, null);
out = new FileOutputStream(fileName);
while (true) {
/* Check for Cancellation and Shutdown */
if (monitor.isCanceled() || Controller.getDefault().isShuttingDown()) {
canceled = true;
return Status.CANCEL_STATUS;
}
/* Read from Stream */
int read = in.read(buffer);
if (read == -1)
break;
out.write(buffer, 0, read);
}
} catch (FileNotFoundException e) {
error = e;
Activator.safeLogError(e.getMessage(), e);
} catch (IOException e) {
error = e;
Activator.safeLogError(e.getMessage(), e);
} catch (ConnectionException e) {
error = e;
Activator.safeLogError(e.getMessage(), e);
} finally {
monitor.done();
if (out != null) {
try {
out.close();
} catch (IOException e) {
Activator.safeLogError(e.getMessage(), e);
}
}
if (in != null) {
try {
if ((canceled || error != null) && in instanceof IAbortable)
((IAbortable) in).abort();
else
in.close();
} catch (IOException e) {
Activator.safeLogError(e.getMessage(), e);
}
}
}
return Status.OK_STATUS;
}
};
downloadJob.schedule();
}
} catch (ConnectionException e) {
Activator.safeLogError(e.getMessage(), e);
}
}