/**
  * Download the resource at the given url
  *
  * @param url to download
  * @return created file or null if a problem occured
  * @throws Exception
  */
 public static File downloadCover(URL url, String pID) throws Exception {
   String id = pID;
   // Check if url is known in cache
   String idCache = urlCache.get(url);
   if (idCache != null) {
     id = idCache;
   }
   // check if file is not already downloaded or being downloaded
   File file = Util.getCachePath(url, id);
   if (file.exists()) {
     return file;
   }
   HttpURLConnection connection = NetworkUtils.getConnection(url, proxy);
   File out = Util.getCachePath(url, id);
   BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(out));
   BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
   int i;
   while ((i = bis.read()) != -1) {
     bos.write(i);
   }
   bos.close();
   bis.close();
   connection.disconnect();
   urlCache.put(url, id);
   return out;
 }
 /**
  * Download the resource at the given url
  *
  * @param url to download
  * @param Use cache : store file in image cache
  * @throws Exception
  */
 public static void download(URL url, File fDestination) throws Exception {
   HttpURLConnection connection = NetworkUtils.getConnection(url, proxy);
   BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fDestination));
   BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
   int i;
   while ((i = bis.read()) != -1) {
     bos.write(i);
   }
   bos.close();
   bis.close();
   connection.disconnect();
 }
 /**
  * Download the cover list
  *
  * @param url to download
  * @throws Exception
  * @return result as an array of bytes, null if a problem occured
  */
 public static String downloadHtml(URL url, String charset) throws Exception {
   return NetworkUtils.readURL(NetworkUtils.getConnection(url, proxy), charset);
 }