Examples of DiskManagerFileInfo


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

    Object[] dataSources = tv.getSelectedDataSources(true);
    List<SelectedContent> listSelected = new ArrayList<SelectedContent>(
        dataSources.length);
    for (Object ds : dataSources) {
      if (ds instanceof DiskManagerFileInfo) {
        DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
        listSelected.add(new SelectedContent(fileInfo.getDownloadManager(),
            fileInfo.getIndex()));
      }
    }
    SelectedContentManager.changeCurrentlySelectedContent(tv.getTableID(),
        listSelected.toArray(new SelectedContent[0]), tv);
  }
View Full Code Here

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

  }

 
  // @see com.aelitis.azureus.ui.common.table.TableSelectionListener#defaultSelected(com.aelitis.azureus.ui.common.table.TableRowCore[])
  public void defaultSelected(TableRowCore[] rows, int stateMask) {
    DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) tv.getFirstSelectedDataSource();
   
    if ( fileInfo == null ){
      return;
    }
   
    AZ3Functions.provider az3 = AZ3Functions.getProvider();
   
    if ( az3 != null ){
     
      DownloadManager dm = fileInfo.getDownloadManager();
     
      if ( az3.canPlay(dm, fileInfo.getIndex()) || (stateMask & SWT.CONTROL) > 0 ){
       
        az3.play( dm, fileInfo.getIndex() );
       
        return;
      }
    }
   
    if ( fileInfo.getAccessMode() == DiskManagerFileInfo.READ ){
     
      Utils.launch(fileInfo);
    }
  }
View Full Code Here

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

    try {
      refreshing = true;
      if (tv.isDisposed())
        return;
 
      DiskManagerFileInfo files[] = getFileInfo();

      if (files != null && (this.force_refresh || !doAllExist(files))) {
        this.force_refresh = false;

        List<DiskManagerFileInfo> datasources = tv.getDataSources();
        if(datasources.size() == files.length)
        {
          // check if we actually have to replace anything
          ArrayList<DiskManagerFileInfo> toAdd = new ArrayList<DiskManagerFileInfo>(Arrays.asList(files));
          ArrayList<DiskManagerFileInfo> toRemove = new ArrayList<DiskManagerFileInfo>();
          for(int i = 0;i < datasources.size();i++)
          {
            DiskManagerFileInfo info = datasources.get(i);
           
            if(files[info.getIndex()] == info)
              toAdd.set(info.getIndex(), null);
            else
              toRemove.add(info);
          }
          tv.removeDataSources(toRemove.toArray(new DiskManagerFileInfo[toRemove.size()]));
          tv.addDataSources(toAdd.toArray(new DiskManagerFileInfo[toAdd.size()]));
          ((TableViewSWTImpl)tv).tableInvalidate();
        } else
        {
          tv.removeAllTableRows();
         
          DiskManagerFileInfo filesCopy[] = new DiskManagerFileInfo[files.length];
          System.arraycopy(files, 0, filesCopy, 0, files.length);

          tv.addDataSources(filesCopy);
        }
View Full Code Here

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

   *
   * @since 3.0.0.7
   */
  private boolean doAllExist(DiskManagerFileInfo[] files) {
    for (int i = 0; i < files.length; i++) {
      DiskManagerFileInfo fileinfo = files[i];

      // We can't just use tv.dataSourceExists(), since it does a .equals()
      // comparison, and we want a reference comparison
      TableRowCore row = tv.getRow(fileinfo);
      if (row == null) {
View Full Code Here

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

            // 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.disk.DiskManagerFileInfo

                try{
                  state.suppressStateSave(true);
                                 
                  for ( int i=0; i<fileInfos.length; i++ ){
                   
                    DiskManagerFileInfo fileInfo = fileInfos[i];
                   
                    File base_file = fileInfo.getFile( false );
                   
                    File existing_link = state.getFileLink( base_file );
                   
                    if ( existing_link == null && base_file.exists()){
                     
View Full Code Here

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

    try {
      state.suppressStateSave(true);

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

        DiskManagerFileInfo fileInfo = fileInfos[i];

        File base_file = fileInfo.getFile(false);

        File existing_link = state.getFileLink(base_file);

        if (existing_link == null && !base_file.exists()) {

          String name = base_file.getName();
          String ext = FileUtil.getExtension(name);
          int extLength = ext.length();
          name = name.substring(0, name.length() - extLength);

          // Java appears to be pretending
          // each unicode character is 3 bytes long.  If the limit
          // on a name is 256 two byte characters, then in theory,
          // the limit is 170 unicode characters.  Instead of assuming
          // that's the case, let's just walk back until the name
          // is accepted.
          // Bail at 50 just for the fun of it (plus most filenames
          // are short, so we can skip the Canonical call)
          int origLength = name.length();
          if (origLength > 50) {
            File parentFile = base_file.getParentFile();

            // We don't get "File name too long" on getCanonicalPath
            // unless the dir is there
            // I Wonder if we should remove the dirs after using them
            // FMFileImpl will create dirs again
            parentFile.mkdirs();

            File newFile = null;
            boolean first = true;
            while (name.length() > 50) {
              try {
                newFile = new File(parentFile, name + ext);
                newFile.getCanonicalPath();

                if (first) {
                  break;
                }

                // it worked, but the new name might already exist
                int fixNameID = 0xFF; // always 3 digits :)
                boolean redo;
                do {
                  redo = false;
                  for (int j = 0; j < i; j++) {
                    DiskManagerFileInfo convertedFileInfo = fileInfos[j];
                    if (newFile.equals(convertedFileInfo.getFile(true))) {
                      do {
                        fixNameID++;
                        if (fixNameID >= 0xFFF) {
                          // exit, will fail later :(
                          break;
                        }
                        name = name.substring(0, name.length() - 3)
                            + Integer.toHexString(fixNameID);
                        newFile = new File(parentFile, name + ext);
                      } while (newFile.equals(convertedFileInfo.getFile(true)));
                      redo = fixNameID <= 0xFFF;
                      break;
                    }
                  }
                } while (redo);
View Full Code Here

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

    }
   
      // no underlying download, lash something up
   
    return(
      new DiskManagerFileInfo()
      {
        public void
        setPriority(
          int b )
        {
View Full Code Here

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

        if (datasource instanceof Peer) {
          return datasource;
        }
       
        if (datasource instanceof org.gudy.azureus2.core3.disk.DiskManagerFileInfo) {
          DiskManagerFileInfo fileInfo = (org.gudy.azureus2.core3.disk.DiskManagerFileInfo) datasource;
          if (fileInfo != null) {
            try {
              return new org.gudy.azureus2.pluginsimpl.local.disk.DiskManagerFileInfoImpl(
                  DownloadManagerImpl.getDownloadStatic(fileInfo.getDownloadManager()),
                  fileInfo);
            } catch (DownloadException e) { /* Ignore */
            }
          }
        }
 
View Full Code Here

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

    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++){
             
              TOTorrentFile  torrent_file = files[j].getTorrentFile();
             
              byte[][]  comps = torrent_file.getPathComponents();
             
              if ( comps.length == bits.size()){
               
                boolean  match = true;
               
                for (int k=0;k<comps.length;k++){
                                                 
                  if ( !Arrays.equals( comps[k], (byte[])bits.get(k))){
                   
                    match  = false;
                   
                    break;
                  }
                }
               
                if ( match ){
                 
                  target_file   = files[j];
                                 
                  break;
                }
              }
             
              file_offset += torrent_file.getLength();
            }
          }
        }else{
         
          line = line.toLowerCase( MessageText.LOCALE_ENGLISH );
         
          if ( line.startsWith( "range" ) && target_file != null ){
           
            line = line.substring(5).trim();
           
            if ( line.startsWith(":" )){
                 
              String  range_str = line.substring(1).trim();
             
              if ( range_str.startsWith( "bytes=" )){
               
                long  file_length = target_file.getLength();
               
                StringTokenizer tok2 = new StringTokenizer( range_str.substring( 6 ), "," );
               
                while( tok2.hasMoreTokens()){
                 
                  String  range = tok2.nextToken();
                 
                  try{
                    int  pos = range.indexOf('-');
                   
                    if ( pos != -1 ){
                     
                      String  lhs = range.substring( 0,pos);
                      String  rhs = range.substring(pos+1);
                     
                      long  start;
                      long  end;
                     
                      if ( lhs.length() == 0 ){
                       
                          // -222 is last 222 bytes of file
                       
                        end   = file_length - 1;
                        start   = file_length - Long.parseLong( rhs );
                       
                      }else if ( rhs.length() == 0 ){
                       
                        end   = file_length - 1;
                        start   = Long.parseLong( lhs );
                       
                      }else{
                       
                        start   = Long.parseLong( lhs );
                        end   = Long.parseLong( rhs );
                     
                     
                      ranges.add( new long[]{ start, end });
                    }
                  }catch( Throwable e ){
                  }
                }
              }
             
              if ( ranges.size() == 0 ){
             
                  log( "Invalid range specification: '" + line + "'" );         

                sendAndClose( getManager().getRangeNotSatisfiable());
               
                return;
              }
            }
          }else if ( line.indexOf( "keep-alive" ) != -1 ){
           
            keep_alive  = true;           
          }
        }
      }
    }

    if ( target_file == null ){
     
      log( "Failed to find file '" + target_str + "'" );

      sendAndClose( getManager().getNotFound());
     
      return;
    }
   
    try{
      String  name = target_file.getFile( true ).getName();
   
      int  pos = name.lastIndexOf( "." );
     
      if ( pos != -1 ){
       
        setContentType( HTTPUtils.guessContentTypeFromFileType( name.substring( pos+1 )));
      }
    }catch( Throwable e ){
    }
   
    long  file_length = target_file.getLength();
   
    boolean  partial_content =  ranges.size() > 0;
   
    if ( !partial_content ){
     
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.