Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
*Fix: downloadAndSave method return false if download unsuccessful
Browse files Browse the repository at this point in the history
  • Loading branch information
Zolli committed Mar 18, 2013
1 parent 5cabe1b commit 214b895
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/com/Zolli/EnderCore/Utils/networkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class networkUtils {
* @param saveLocation The location on the file is saved
* @return int The download rate
*/
public static int downloadAndSave(String Url, String saveLocation, simpleLogger logger) throws Exception {
@SuppressWarnings("finally")
public static boolean downloadAndSave(String Url, String saveLocation, simpleLogger logger) throws Exception {
BufferedInputStream in = null;
BufferedOutputStream out = null;
File fl = new File(saveLocation);
Expand Down Expand Up @@ -51,14 +52,16 @@ public static int downloadAndSave(String Url, String saveLocation, simpleLogger
transferRate = (int) ((endTime-startTime)/fileLength);
} catch(Exception e) {
e.printStackTrace();
return false;
} finally {
out.flush();
out.close();
in.close();
logger.log(Level.INFO, "Download successfully. Average download rate is: " + transferRate + "Kb/s");
return true;
}
}
return transferRate;
return true;
}

/**
Expand Down

0 comments on commit 214b895

Please sign in to comment.