示例#1
0
    @Override
    public void handle(HttpRequest request, HttpResponse response, HttpContext context)
        throws HttpException, IOException {

      AbstractHttpEntity entity;
      String uri = request.getRequestLine().getUri();
      int i = uri.indexOf(LIBRARY_URL);
      String sha1 = uri.substring(i + LIBRARY_URL.length());
      if (sha1.indexOf("?") != -1) {
        sha1 = sha1.substring(0, sha1.indexOf("?"));
      }
      System.out.println("sha1:" + sha1);

      URN urn = new URNImpl(com.limegroup.gnutella.URN.createSHA1Urn(sha1));
      if (libraryManager.getLibraryManagedList().contains(urn)) {
        FileDesc fileDesc = libraryManager.getLibraryManagedList().getFileDescsByURN(urn).get(0);
        entity = new NFileEntity(fileDesc.getFile(), "application/binary");
        entity.setContentType("application/binary");
        response.setHeader(
            "Content-disposition", "attachment; filename=\"" + fileDesc.getFileName() + "\";");
      } else {
        entity = new NStringEntity("File not found: " + sha1);
        entity.setContentType("text/plain");
      }
      response.setEntity(entity);
    }
示例#2
0
  /**
   * kills all in-network downloaders whose URNs are not listed in the list of updates. Deletes any
   * files in the folder that are not listed in the update message.
   */
  private void killObsoleteUpdates(List<? extends DownloadInformation> toDownload) {
    if (!downloadManager.get().isSavedDownloadsLoaded()
        || !fileManager.get().getManagedFileList().isLoadFinished()) return;

    if (_killingObsoleteNecessary) {
      _killingObsoleteNecessary = false;
      downloadManager.get().killDownloadersNotListed(toDownload);

      Set<URN> urns = new HashSet<URN>(toDownload.size());
      for (DownloadInformation data : toDownload) urns.add(data.getUpdateURN());

      List<FileDesc> shared =
          fileManager
              .get()
              .getGnutellaFileList()
              .getFilesInDirectory(LibraryUtils.PREFERENCE_SHARE);
      for (FileDesc fd : shared) {
        if (fd.getSHA1Urn() != null && !urns.contains(fd.getSHA1Urn())) {
          fileManager.get().getManagedFileList().remove(fd.getFile());
          fd.getFile().delete();
        }
      }
    }
  }