protected static synchronized void download(String location, String filename) throws IOException {
    URLConnection connection = new URL(location).openConnection();
    connection.setUseCaches(false);
    lastModified = connection.getLastModified();
    String destination = "lib" + File.separator + filename;
    File parentDirectory = new File(destination).getParentFile();

    if (parentDirectory != null) {
      parentDirectory.mkdirs();
    }

    InputStream in = connection.getInputStream();
    OutputStream out = new FileOutputStream(destination);

    byte[] buffer = new byte[65536];
    Integer currentCount = 0;

    while (!cancelled)
    {
      int count = in.read(buffer);

      if (count < 0)
      {
        break;
      }
      out.write(buffer, 0, count);
      currentCount += count;
    }

    in.close();
    out.close();
  }