Examples of TOTorrent


Examples of org.gudy.azureus2.core3.torrent.TOTorrent

  setTorrentResumeDataNearlyComplete(
    DownloadManagerState  download_manager_state )
  {
      // backwards compatability, resume data key is the dir
   
    TOTorrent  torrent = download_manager_state.getTorrent();
   
    long  piece_count = torrent.getNumberOfPieces();
   
    byte[] resume_pieces = new byte[(int)piece_count];
   
    Arrays.fill( resume_pieces, PIECE_DONE );
View Full Code Here

Examples of org.gudy.azureus2.core3.torrent.TOTorrent

    File fDst = new File(torrentName);
   
    if(parameters.get("verbose") != null)
      verbose = true;
   
    TOTorrent torrent = null;
    String pieceSizeStr = (String) parameters.get("force_piece_size_pow2");
    if(pieceSizeStr != null) {
      try {    
        long pieceSize = 1l << Integer.parseInt(pieceSizeStr);
        TOTorrentCreator creator = TOTorrentFactory.createFromFileOrDirWithFixedPieceLength(fSrc,url,pieceSize);
        creator.addListener( this );
        torrent = creator.create();
      }catch(Exception e) {
        e.printStackTrace();
        return;
      }
    } else {
      try {
        TOTorrentCreator creator = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(fSrc,url);
        creator.addListener( this );
        torrent = creator.create();
      } catch(Exception e) {
        e.printStackTrace();
        return;
      }
    }
   
    String comment = (String) parameters.get("comment");
    if(comment != null) {
      torrent.setComment(comment);
    }
   
    String announceList = (String) parameters.get("announce-list");
    if(announceList != null) {
      StringTokenizer st = new StringTokenizer(announceList,"|");
      List list = new ArrayList();
      List urls = new ArrayList();
      while(st.hasMoreTokens()) {
        String _url = st.nextToken();
        urls.add(_url);       
      }
      list.add(urls);           
     
      TorrentUtils.listToAnnounceGroups(list, torrent);
    }
   
    try {
      torrent.serialiseToBEncodedFile(fDst);
    } catch(Exception e) {
      e.printStackTrace();
    }
   
  }
View Full Code Here

Examples of org.gudy.azureus2.core3.torrent.TOTorrent

          public void runSupport() {

            for (int i = 0; i < fileNames.length; i++) {

              try {
                TOTorrent t = TorrentUtils.readFromFile(new File(path,
                    fileNames[i]), true);

                core.getTrackerHost().hostTorrent(t, true, true);

              } catch (Throwable e) {
View Full Code Here

Examples of org.gudy.azureus2.core3.torrent.TOTorrent

            // Build eventData here because on OSX, selection gets cleared
            // by the time dragSetData occurs
            Object[] selectedDownloads = tv.getSelectedDataSources().toArray();
            eventData = "DiskManagerFileInfo\n";
            TOTorrent torrent = manager.getTorrent();
            for (int i = 0; i < selectedDownloads.length; i++) {
              DiskManagerFileInfo fi = (DiskManagerFileInfo) selectedDownloads[i];
             
              try {
                eventData += torrent.getHashWrapper().toBase32String() + ";"
                    + fi.getIndex() + "\n";
              } catch (Exception e) {
              }
            }
          }
View Full Code Here

Examples of org.gudy.azureus2.core3.torrent.TOTorrent

        FileUtil.mkdirs(download_dir);
      }
     
      final File  data_dir    = download_dir==null?torrent_file.getParentFile():download_dir;
     
      final TOTorrent  torrent = torrent_holder[0];
     
      TorrentUtils.setFlag( torrent, TorrentUtils.TORRENT_FLAG_LOW_NOISE, true );

      torrent.serialiseToBEncodedFile( torrent_file );
     
        // see if already there in an error state and delete if so
     
      try{
        Download existing = download_manager.getDownload( torrent.getHash());
     
        if ( existing != null ){
         
          int  existing_state = existing.getState();
         
          if ( existing_state == Download.ST_ERROR || existing_state == Download.ST_STOPPED ){
           
            informActivity( getLogIndent() + "Deleting existing stopped/error state download for " + name );

            existing.remove( true, true );
          }
        }
      }catch( Throwable e ){ 
      }
     
      if ( persistent ){
       
        download = download_manager.addDownload( new TorrentImpl(torrent), torrent_file, data_dir );
       
      }else{
       
        download = download_manager.addNonPersistentDownload( new TorrentImpl(torrent), torrent_file, data_dir );
      }
     
      download.moveTo(1);   
     
      download.setForceStart( true );
     
      // Prevents any move-on-completion or move-on-removal behaviour happening.
      download.setFlag(Download.FLAG_DISABLE_AUTO_FILE_MOVE, true);
     
      download_manager.addListener(
        new DownloadManagerListener()
        {
          public void
          downloadAdded(
            Download  download )
          {         
          }
         
          public void
          downloadRemoved(
            Download  _download )
          {
            if ( download == _download ){
             
              ResourceDownloaderTorrentImpl.this.downloadRemoved( torrent_file, data_dir );
            }
          }
        });
           
      download.addListener(
        new DownloadListener()
        {
          public void
          stateChanged(
            final Download    download,
            int        old_state,
            int        new_state )
          {   
            // System.out.println( "state change:" + old_state + "->" + new_state );
           
            if ( new_state == Download.ST_SEEDING ){
             
              download.removeListener( this );
             
              PluginInitializer.getDefaultInterface().getUtilities().createThread(
                "resource complete event dispatcher",
                new Runnable()
                {
                  public void
                  run()
                  {
                    downloadSucceeded( download, torrent_file, data_dir );
                  }
                });
             
            }
          }

          public void
          positionChanged(
            Download  download,
            int     oldPosition,
            int     newPosition )
          {
          }
        });
       
      Thread  t =
        new AEThread( "RDTorrent percentage checker")
        {
          public void
          runSupport()
          {
            int  last_percentage = 0;
           
            while( result == null ){
                           
              int  this_percentage = download.getStats().getDownloadCompleted(false)/10;
             
              long  total  = torrent.getSize();
                           
              if ( this_percentage != last_percentage ){
               
                reportPercentComplete( ResourceDownloaderTorrentImpl.this, this_percentage );
             
View Full Code Here

Examples of org.gudy.azureus2.core3.torrent.TOTorrent

        if (optionalHash != null) {
          hash = new HashWrapper(optionalHash);
        } else {
          // This does not trigger locale decoding :)
          TOTorrent torrent = TorrentUtils.readFromFile(fDest, false);
          hash = torrent.getHashWrapper();
        }
       
        if (hash != null) {
          removeFromAddingDM = true;
View Full Code Here

Examples of org.gudy.azureus2.core3.torrent.TOTorrent

           
            saved_hashfails = lHashFailsBytes.longValue();
           
          }else if ( lHashFailsCount != null) {
           
            TOTorrent torrent = download_manager.getTorrent();
           
            if ( torrent != null ){
           
              saved_hashfails = lHashFailsCount.longValue() * torrent.getPieceLength();
            }
          }
         
          Long lPosition = (Long) save_download_state.get("position");
         
            // 2.2.0.1 - category moved to downloadstate - this here for
            // migration purposes
         
          String sCategory = null;
          if (save_download_state.containsKey("category")){
            try{
              sCategory = new String((byte[]) save_download_state.get("category"), Constants.DEFAULT_ENCODING);
            }catch( UnsupportedEncodingException e ){
             
              Debug.printStackTrace(e);
            }
          }
 
          if (sCategory != null) {
            Category cat = CategoryManager.getCategory(sCategory);
            if (cat != null) download_manager.getDownloadState().setCategory(cat);
          }
         
          download_manager.requestAssumedCompleteMode();
         
          if (lDownloaded != null && lUploaded != null) {
            boolean bCompleted = download_manager.isDownloadComplete(false);
           
            long lUploadedValue = lUploaded.longValue();
           
            long lDownloadedValue = lDownloaded.longValue();
           
            if ( bCompleted && (lDownloadedValue == 0)){
             
              //Gudy : I say if the torrent is complete, let's simply set downloaded
              //to size in order to see a meaningfull share-ratio
                //Gudy : Bypass this horrible hack, and I don't care of first priority seeding...
                /*
                if (lDownloadedValue != 0 && ((lUploadedValue * 1000) / lDownloadedValue < minQueueingShareRatio) )
                  lUploadedValue = ( download_manager.getSize()+999) * minQueueingShareRatio / 1000;
                  */
              // Parg: quite a few users have complained that they want "open-for-seeding" torrents to
              // have an infinite share ratio for seeding rules (i.e. so they're not first priority)
            
            int  dl_copies = COConfigurationManager.getIntParameter("StartStopManager_iAddForSeedingDLCopyCount");
               
            lDownloadedValue = download_manager.getSize() * dl_copies;
           
            download_manager.getDownloadState().setFlag( DownloadManagerState.FLAG_ONLY_EVER_SEEDED, true );
            }
           
            saved_data_bytes_downloaded  = lDownloadedValue;
            saved_data_bytes_uploaded    = lUploadedValue;
          }
 
          if (lPosition != null)
            download_manager.setPosition(lPosition.intValue());
          // no longer needed code
          //  else if (dm_stats.getDownloadCompleted(false) < 1000)
          //  dm.setPosition(bCompleted ? numCompleted : numDownloading);
 
          Long lSecondsDLing = (Long)save_download_state.get("secondsDownloading");
          if (lSecondsDLing != null) {
            saved_SecondsDownloading = lSecondsDLing.longValue();
          }
 
          Long lSecondsOnlySeeding = (Long)save_download_state.get("secondsOnlySeeding");
          if (lSecondsOnlySeeding != null) {
            saved_SecondsOnlySeeding = lSecondsOnlySeeding.longValue();
          }
         
          Long already_allocated = (Long)save_download_state.get( "allocated" );
          if( already_allocated != null && already_allocated.intValue() == 1 ) {
            download_manager.setDataAlreadyAllocated( true );
          }
         
          Long creation_time = (Long)save_download_state.get( "creationTime" );
         
          if ( creation_time != null ){
           
            long  ct = creation_time.longValue();
           
            if ( ct < SystemTime.getCurrentTime()){
           
              download_manager.setCreationTime( ct );
            }
          }
         
        }else{
         
            // no stats, bodge the uploaded for seeds
          
          if ( dm_stats.getDownloadCompleted(false) == 1000 ){
                
            int  dl_copies = COConfigurationManager.getIntParameter("StartStopManager_iAddForSeedingDLCopyCount");
           
            saved_data_bytes_downloaded = download_manager.getSize()*dl_copies;
          }
        }
       
        dm_stats.restoreSessionTotals(
          saved_data_bytes_downloaded,
          saved_data_bytes_uploaded,
          saved_discarded,
          saved_hashfails,
          saved_SecondsDownloading,
          saved_SecondsOnlySeeding );
       
        boolean isCompleted = download_manager.isDownloadComplete(false);
    
        if (download_manager.getPosition() == -1) {
          int endPosition = 0;
          for (int i = 0; i < managers_cow.size(); i++) {
            DownloadManager dm = (DownloadManager) managers_cow.get(i);
            boolean dmIsCompleted = dm.isDownloadComplete(false);
            if (dmIsCompleted == isCompleted)
              endPosition++;
          }
          download_manager.setPosition(endPosition + 1);
        }
       
        // Even though when the DownloadManager was created, onlySeeding was
        // most likely set to true for completed torrents (via the Initializer +
        // readTorrent), there's a chance that the torrent file didn't have the
        // resume data.  If it didn't, but we marked it as complete in our
        // downloads config file, we should set to onlySeeding
        download_manager.requestAssumedCompleteMode();

        List  new_download_managers = new ArrayList( managers_cow );
       
        new_download_managers.add(download_manager);
       
        managers_cow  = new_download_managers;
       
        TOTorrent  torrent = download_manager.getTorrent();
       
        if ( torrent != null ){
         
          try{
            manager_map.put( new HashWrapper(torrent.getHash()), download_manager );
           
          }catch( TOTorrentException e ){
           
            Debug.printStackTrace( e );
          }
View Full Code Here

Examples of org.gudy.azureus2.core3.torrent.TOTorrent

     
      new_download_managers.remove(manager);
     
      managers_cow  = new_download_managers;
     
      TOTorrent  torrent = manager.getTorrent();
     
      if ( torrent != null ){
       
        try{
          manager_map.remove(new HashWrapper(torrent.getHash()));
         
        }catch( TOTorrentException e ){
         
          Debug.printStackTrace( e );
        }
      }

    }finally{
     
      managers_mon.exit();
    }
 
      // when we remove a download manager from Azureus this is the time to remove it from the record of
      // created torrents if present
   
    TOTorrent  torrent = manager.getTorrent();
   
    if ( torrent != null ){
     
      TorrentUtils.removeCreatedTorrent( torrent );
    }
View Full Code Here

Examples of org.gudy.azureus2.core3.torrent.TOTorrent

      for (int i = 0; i < managers_cow.size(); i++) {
        DownloadManager dm = (DownloadManager) managers_cow.get(i);
       
          DownloadManagerStats dm_stats = dm.getStats();
          Map dmMap = new HashMap();
          TOTorrent  torrent = dm.getTorrent();
         
          if ( torrent != null ){
            try{
              dmMap.put( "torrent_hash", torrent.getHash());
             
            }catch( TOTorrentException e ){
             
              Debug.printStackTrace(e);
            }
View Full Code Here

Examples of org.gudy.azureus2.core3.torrent.TOTorrent

     
      setState( initial_state, true );
    }
   
 
    TOTorrent torrent = download_manager.getTorrent();

    if (torrent != null) {
     
      try{
        peer_manager_registration = PeerManager.getSingleton().registerLegacyManager( torrent.getHashWrapper(), this );
       
      }catch( TOTorrentException e ){
       
        Debug.printStackTrace(e);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.