Examples of DiskManager


Examples of org.gudy.azureus2.core3.disk.DiskManager

      img = null;
    }

    DownloadManager  download_manager = file==null?null:file.getDownloadManager();
   
    DiskManager    disk_manager = download_manager==null?null:download_manager.getDiskManager();
    PEPeerManager  peer_manager = download_manager==null?null:download_manager.getPeerManager();
   
    if ( file == null || disk_manager == null || peer_manager == null ) {
      GC gc = new GC(fileInfoCanvas);
      gc.fillRectangle(bounds);
      gc.dispose();

      return;
    }

    int  first_piece = file.getFirstPieceNumber();
    int  num_pieces  = file.getNbPieces();
   
    int iNumCols = bounds.width / BLOCK_SIZE;
    int iNeededHeight = (((num_pieces - 1) / iNumCols) + 1)
        * BLOCK_SIZE;
    if (sc.getMinHeight() != iNeededHeight) {
      sc.setMinHeight(iNeededHeight);
      sc.layout(true, true);
      bounds = fileInfoCanvas.getClientArea();
    }

    img = new Image(fileInfoCanvas.getDisplay(), bounds.width, iNeededHeight);
    GC gcImg = new GC(img);

    try {
      gcImg.setBackground(fileInfoCanvas.getBackground());
      gcImg.fillRectangle(0, 0, bounds.width, bounds.height);


      DiskManagerPiece[]   dm_pieces = disk_manager.getPieces();
      PEPiece[]      pe_pieces = peer_manager.getPieces();

      int iRow = 0;
      int iCol = 0;
     
View Full Code Here

Examples of org.gudy.azureus2.core3.disk.DiskManager

  }
 
    public void
    saveDownload()
    {
      DiskManager disk_manager = controller.getDiskManager();
   
      if ( disk_manager != null ){
     
        disk_manager.saveState();
      }
   
      download_manager_state.save();
    }
View Full Code Here

Examples of org.gudy.azureus2.core3.disk.DiskManager

     
      TRTrackerAnnouncer  tc = tracker_client;
     
      if ( tc != null ){
       
        DiskManager  dm = getDiskManager();
       
          // only report "complete" if we really are complete, not a dnd completion event
       
        if ( dm != null && dm.getRemaining() == 0 ){
         
          tc.complete( never_downloaded );
        }
      }
  }
View Full Code Here

Examples of org.gudy.azureus2.core3.disk.DiskManager

    if (current_save_location.equals(new_save_location)) {
        // null operation
      return;
    }

    DiskManager  dm = getDiskManager();
   
    if ( dm == null || dm.getFiles() == null){

      if ( !old_file.exists()){
         
        // files not created yet
         
        FileUtil.mkdirs(new_save_location.getParentFile());
         
        setTorrentSaveDir(new_save_location.getParent().toString(), new_save_location.getName());
       
        return;
      }
       
      try{
        new_save_location  = new_save_location.getCanonicalFile();
       
      }catch( Throwable e ){
       
        Debug.printStackTrace(e);
      }
     
      if ( old_file.equals( new_save_location )){
       
        // nothing to do
       
      } else if (torrent.isSimpleTorrent()) {
        // Have to keep the file name in sync if we're renaming.
        if (controller.getDiskManagerFileInfo()[0].setLinkAtomic(new_save_location)) {
          setTorrentSaveDir( new_save_location.getParentFile().toString(), new_save_location.getName());
        } else {throw new DownloadManagerException( "rename operation failed");}
       
      }else{

        if (FileUtil.isAncestorOf(old_file, new_save_location)) {
           
                Logger.logTextResource(new LogAlert(this, LogAlert.REPEATABLE,
              LogAlert.AT_ERROR, "DiskManager.alert.movefilefails"),
              new String[] {old_file.toString(), "Target is sub-directory of files" });
               
                throw( new DownloadManagerException( "rename operation failed" ));
        }
       
        // The files we move must be limited to those mentioned in the torrent.
        final HashSet files_to_move = new HashSet();

              // Required for the adding of parent directories logic.
              files_to_move.add(null);
              DiskManagerFileInfo[] info_files = controller.getDiskManagerFileInfo();
              for (int i=0; i<info_files.length; i++) {
                  File f = info_files[i].getFile(true);
                  try {f = f.getCanonicalFile();}
                  catch (IOException ioe) {f = f.getAbsoluteFile();}
                  boolean added_entry = files_to_move.add(f);

                  /**
                   * Start adding all the parent directories to the
                   * files_to_move list. Doesn't matter if we include
                   * files which are outside of the file path, the
                   * renameFile call won't try to move those directories
                   * anyway.
                   */
                  while (added_entry) {
                      f = f.getParentFile();
                      added_entry = files_to_move.add(f);
                  }
              }
        FileFilter ff = new FileFilter() {
          public boolean accept(File f) {return files_to_move.contains(f);}
        };
       
        if ( FileUtil.renameFile( old_file, new_save_location, false, ff )){
             
          setTorrentSaveDir( new_save_location.getParentFile().toString(), new_save_location.getName());
       
        }else{
         
          throw( new DownloadManagerException( "rename operation failed" ));
        }
      }
    }else{
      dm.moveDataFiles( new_save_location.getParentFile(), new_save_location.getName());
    }
  }
View Full Code Here

Examples of org.gudy.azureus2.core3.disk.DiskManager

   
      try{
         // Data files don't exist, so we just don't do anything.
          if (!getSaveLocation().exists()) {return;}
         
          DiskManager dm = this.getDiskManager();
          if (dm != null) {
            dm.downloadRemoved();
            return;
          }
               
          SaveLocationChange move_details;
          move_details = DownloadManagerMoveHandler.onRemoval(this);
View Full Code Here

Examples of org.gudy.azureus2.core3.disk.DiskManager

  {
    manager      = _manager;
    connection    = _connection;
    peer      = _peer;
   
    DiskManager dm = peer.getManager().getDiskManager();
   
    long  last_modified = 0;
   
    try{
      last_modified = dm.getFiles()[0].getFile(true).lastModified();
           
    }catch( Throwable e ){
    }
   
    last_modified_date = TimeFormatter.getHTTPDate( last_modified );
View Full Code Here

Examples of org.gudy.azureus2.core3.disk.DiskManager

      return;
    }   
   
    PEPeerControl  control = getPeerControl();
   
    DiskManager  dm = control.getDiskManager();
   
    if ( dm == null ){
     
      Debug.out( "Disk manager is null" );
     
      throw( new IOException( "Disk manager unavailable" ));
    }
         
    TOTorrent  to_torrent = dm.getTorrent();
       
    char[]  chars = header.toCharArray();
   
    int  last_pos   = 0;
    int  line_num  = 0;
   
    String        target_str  = null;
   
    DiskManagerFileInfo  target_file = null;
   
    long  file_offset  = 0;
   
    List<long[]>  ranges = new ArrayList<long[]>();
   
    boolean  keep_alive  = false;
   
    for (int i=1;i<chars.length;i++){
     
      if ( chars[i-1] == '\r' && chars[i] == '\n' ){
       
        String  line = new String( chars, last_pos, i - last_pos ).trim();
       
        last_pos = i;
       
        line_num++;
       
        // System.out.println( "line " + line_num + " -> " + line );
       
        if ( line_num == 1 ){
         
          line = line.substring( line.indexOf( "files/" ) + 6 );
         
          int  hash_end = line.indexOf( "/" );
         
          final byte[] old_hash = control.getHash();

          final byte[] new_hash = URLDecoder.decode(line.substring(0, hash_end), "ISO-8859-1").getBytes( "ISO-8859-1" );
         
          if ( !Arrays.equals( new_hash, old_hash )){
           
            switching    = true;
           
            decoder.pauseInternally();
             
            flushRequests(
              new flushListener()
              {
                private boolean triggered;
               
                public void
                flushed()
                {
                  synchronized( this ){
                   
                    if ( triggered ){
                     
                      return;
                    }
                   
                    triggered = true;
                  }
                 
                  getManager().reRoute(
                      HTTPNetworkConnectionFile.this,
                      old_hash, new_hash, header );
                }
              });
             
            return;
          }
         
         
          line = line.substring( hash_end + 1 );
         
          line = line.substring( 0, line.lastIndexOf( ' ' ));
         
          String  file = line;

          if ( to_torrent.isSimpleTorrent()){
           
              // optimise for simple torrents. also support the case where
              // client has the hash but doesn't know the file name
           
            target_file = dm.getFiles()[0];
           
          }else{
           
            target_str  = file;
           
            StringTokenizer  tok = new StringTokenizer( file, "/" );
           
            List<byte[]>  bits = new ArrayList<byte[]>();
           
            while( tok.hasMoreTokens()){
             
              bits.add( URLDecoder.decode(tok.nextToken(), "ISO-8859-1").getBytes( "ISO-8859-1" ));
            }
           
              // latest spec has torrent file name encoded first for non-simple torrents
              // remove it if we find it so we have some backward compat
           
            if ( !to_torrent.isSimpleTorrent() && bits.size() > 1 ){
           
              if ( Arrays.equals( to_torrent.getName(), (byte[])bits.get(0))){
               
                bits.remove(0);
              }
            }
           
            DiskManagerFileInfo[]  files = dm.getFiles();
           
            file_offset  = 0;
           
            for (int j=0;j<files.length;j++){
             
View Full Code Here

Examples of org.gudy.azureus2.core3.disk.DiskManager

          }
        }
       
        if ( state == DownloadManager.STATE_SEEDING ){
       
          DiskManager disk_manager = manager.getDiskManager();
 
          if ( disk_manager != null && disk_manager.getCompleteRecheckStatus() != -1 ){
         
              // wait until recheck is complete before we mark as downloading-complete
           
            is_downloading  = true;
           
View Full Code Here

Examples of org.gudy.azureus2.core3.disk.DiskManager

        try{
          byte[] hash = torrent.getHash();
         
          String  hash_str = ByteFormatter.encodeString( hash );
         
          DiskManager disk = download.getDiskManager();
         
          if ( disk == null ){
           
            byte[] existing = old_cache.get( hash_str );
           
            if ( existing != null ){
             
              new_cache.put( hash_str, existing );
             
              download_map.put( download, existing );
             
            }else{
             
                // assume not yet started and just use the non-skipped files
             
              DiskManagerFileInfo[] files = download.getDiskManagerFileInfo();
             
              byte[] needed = new byte[( torrent.getNumberOfPieces() + 7 ) / 8];

              int  hits = 0;

              for ( DiskManagerFileInfo file: files ){
               
                if ( file.isSkipped()){
                 
                  continue;
                }
               
                int  first_piece   = file.getFirstPieceNumber();
                int  last_piece    = first_piece + file.getNbPieces() - 1;
                               
                int  needed_pos    = first_piece/8;
                int  current_byte  = 0;
                               
                for ( int pos=first_piece;pos<=last_piece;pos++ ){
                 
                  current_byte = current_byte << 1;
                                     
                  current_byte += 1;
                   
                  hits++;
                 
                  if (( pos %8 ) == 7 ){
                   
                    needed[needed_pos++] |= (byte)current_byte;
                   
                    current_byte = 0;
                  }
                }
               
                if ( current_byte != 0 ){
                 
                  needed[needed_pos++] |= (byte)(current_byte << (8 - (last_piece % 8)));
                }
              }
             
              if ( hits > 0 ){
                 
                new_cache.put( hash_str, needed );
                 
                download_map.put( download, needed );
              }
            }
          }else{
         
            DiskManagerPiece[] pieces = disk.getPieces();
           
            byte[] needed = new byte[( pieces.length + 7 ) / 8];
           
            int  needed_pos    = 0;
            int  current_byte  = 0;
View Full Code Here

Examples of org.gudy.azureus2.core3.disk.DiskManager

      if ( now - last_calc_time < 2*1000 ){
       
        return( last_calc );
      }
     
      DiskManager disk = download.getDiskManager();

      if ( disk == null ){
       
        return( last_calc );
      }
     
      DiskManagerPiece[] pieces = disk.getPieces();
     
      int  pos    = 0;
      int  current  = 0;
     
      long remaining = 0;
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.