}
private void finish()
{
status = "Finishing...";
Mediator.post(new DownloadStatusChanged(this));
finished = true;
if(dest.exists())
{
Logger.post(Logger.Level.WARNING, "File already exists: " + getName());
}
else
{
try
{
FileOutputStream out = new FileOutputStream(dest);
for(Segment seg : segments)
{
FileInputStream in = new FileInputStream(seg.getTempFile());
int b;
while((b = in.read()) != -1)
{
out.write(b);
}
out.flush();
in.close();
if(!seg.getTempFile().delete())
{
Logger.post(Logger.Level.WARNING, "Could not delete temp file: " + seg.getTempFile());
}
}
out.close();
status = "Done";
Mediator.post(new DownloadStatusChanged(this));
Logger.post(Logger.Level.INFO, "Finished download: " + getName());
}
catch(IOException ex)
{