⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 downloadmanagerstateimpl.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			}
			
			return( false );
		}
		
		protected TOTorrent
		loadRealState()
		
			throws TOTorrentException
		{					
			// System.out.println("loadReal: " + torrent_file + " dp=" + discard_pieces + ": " + Debug.getCompressedStackTrace().substring(114));
						
			File	saved_file = getStateFile( torrent_hash_wrapper.getBytes() ); 
			
			if ( saved_file.exists()){
				
				try{
					
					return( TorrentUtils.readFromFile( saved_file, true, discard_pieces ));
					
				}catch( Throwable e ){
					
					Debug.out( "Failed to load download state for " + saved_file );
				}
			}
			
				// try reading from original
			
			TOTorrent original_torrent = TorrentUtils.readFromFile( new File(torrent_file), true );
			
			torrent_hash_wrapper = original_torrent.getHashWrapper();
			
			saved_file = getStateFile( torrent_hash_wrapper.getBytes()); 
			
			if ( saved_file.exists()){
				
				try{
					return( TorrentUtils.readFromFile( saved_file, true, discard_pieces ));
					
				}catch( Throwable e ){
					
					Debug.out( "Failed to load download state for " + saved_file );
				}
			}
									
				// we must copy the torrent as we want one independent from the
				// original (someone might still have references to the original
				// and do stuff like write it somewhere else which would screw us
				// up)
			
			TorrentUtils.copyToFile( original_torrent, saved_file );
			
			return( TorrentUtils.readFromFile( saved_file, true, discard_pieces ));
		}
		
		
		public byte[]
    	getName()
		{
			Map	c = cache;
			
			if ( c != null ){
				
				byte[]	name = (byte[])c.get( "name" );
				
				if ( name != null ){
					
					return( name );
				}
			}
			
			if ( delegate != null ){
				
				return( delegate.getName());
			}
			
	
			return(("Error: " + Debug.getNestedExceptionMessage( fixup_failure )).getBytes()); 
		}
    	
    	public boolean
    	isSimpleTorrent()
    	{
    		if ( fixup()){
    			
    			return( delegate.isSimpleTorrent());
    		}
    		
    		return( false );
    	}
    	
    	public byte[]
    	getComment()
    	{
			Map	c = cache;
			
			if ( c != null ){
				
				return((byte[])c.get( "comment" ));
			}
			
	   		if ( fixup()){
				
				return( delegate.getComment());
			}
	   		
	   		return( null );
    	}

    	public void
    	setComment(
    		String		comment )
       	{
	   		if ( fixup()){
				
				delegate.setComment( comment );
			}
    	}
 
    	public long
    	getCreationDate()
       	{
	   		if ( fixup()){
				
				return( delegate.getCreationDate());
			}
	   		
	   		return( 0 );
    	}
    	
    	public void
    	setCreationDate(
    		long		date )
       	{
	   		if ( fixup()){
				
				delegate.setCreationDate( date );
			}
    	}
    	
    	public byte[]
    	getCreatedBy()
       	{
			Map	c = cache;
			
			if ( c != null ){
				
				return((byte[])c.get( "createdby" ));
			}
			
	   		if ( fixup()){
				
				return( delegate.getCreatedBy());
			}
	   		
	   		return( null );
    	}
    	
    	public boolean
    	isCreated()
       	{
	   		if ( fixup()){
				
				return( delegate.isCreated());
			}
	   		
	   		return( false );
    	}
    	
    	public URL
    	getAnnounceURL()
       	{
	   		if ( fixup()){
				
				return( delegate.getAnnounceURL());
			}
	   		
	   		return( null );
    	}

    	public boolean
    	setAnnounceURL(
    		URL		url )
       	{
	   		if ( fixup()){
				
				return( delegate.setAnnounceURL( url ));
			}
	   		
	   		return( false );
    	}
    	
    	public TOTorrentAnnounceURLGroup
    	getAnnounceURLGroup()
       	{
	   		if ( fixup()){
				
				return( delegate.getAnnounceURLGroup());
			}
	   		
	   		return( null );
    	}
    	 
    	public byte[][]
    	getPieces()
    	
    		throws TOTorrentException
	   	{
	   		if ( fixup()){
				
				return( delegate.getPieces());
			}
	   		
	   		throw( fixup_failure );
    	}
    	

    	public void
    	setPieces(
    		byte[][]	pieces )
    	
    		throws TOTorrentException
	   	{
	   		if ( fixup()){
				
				delegate.setPieces( pieces );
				
				return;
			}
	   		
	   		throw( fixup_failure );
    	}
    	
    	public byte[][]
    	peekPieces()
    	
    		throws TOTorrentException
    	{
    		if ( fixup()){
    			
    			if ( delegate instanceof TorrentUtils.torrentDelegate ){
    				
    				return(((TorrentUtils.torrentDelegate)delegate).peekPieces());
    			}
    			
    			return( delegate.getPieces());
    		}
    		
	   		throw( fixup_failure );
    	}
    	
    	public long
    	getPieceLength()
       	{
	   		if ( fixup()){
				
				return( delegate.getPieceLength());
			}
	   		
	   		return( 0 );
       	}

		public int
    	getNumberOfPieces()
       	{
	   		if ( fixup()){
				
				return( delegate.getNumberOfPieces());
			}
	   		
	   		return( 0 );
    	}
    	
    	public long
    	getSize()
       	{
    		Map	c = cache;
			
			if ( c != null ){
				
				Long	size = (Long)c.get( "size" );
				
				if ( size != null ){
					
					return( size.longValue());
				}
			}
			
	   		if ( fixup()){
				
				return( delegate.getSize());
			}
	   		
	   		return( 0 );
    	}
    	
    	public TOTorrentFile[]
    	getFiles()
       	{
	   		if ( fixup()){
				
				return( delegate.getFiles());
			}
	   		
	   		return( new TOTorrentFile[0] );
    	}
    	 
    	public byte[]
    	getHash()
    				
    		throws TOTorrentException
	   	{
    			// optimise this
    		
    		return( torrent_hash_wrapper.getBytes());
    	}
    	
    	public HashWrapper
    	getHashWrapper()
    				
    		throws TOTorrentException
	   	{
    		return( torrent_hash_wrapper );
    	}

    	public boolean
    	hasSameHashAs(
    		TOTorrent		other )
       	{
    		try{
    			byte[]	other_hash = other.getHash();
    				
    			return( Arrays.equals( getHash(), other_hash ));
    				
    		}catch( TOTorrentException e ){
    			
    			Debug.printStackTrace( e );
    			
    			return( false );
    		}
       	}
    	
    	public boolean
    	getPrivate()
       	{
	   		if ( fixup()){
				
				return( delegate.getPrivate());
			}
	   		
	   		return( false );
    	}
    	
    	public void
    	setPrivate(
    		boolean	_private )
    	
    		throws TOTorrentException
    	   	{
    	   		if ( fixup()){
    				
    				delegate.setPrivate( _private );
    			}
        	}
  
    	public void
    	setAdditionalStringProperty(
    		String		name,
    		String		value )
       	{
	   		if ( fixup()){
				
				delegate.setAdditionalStringProperty( name, value );
			}
    	}
    		
    	public String
    	getAdditionalStringProperty(
    		String		name )
       	{
			Map	c = cache;
			
			if ( c != null && ( name.equals( "encoding") || name.equals( "torrent filename" ))){
								
				byte[] res = (byte[])c.get( name );

				if ( res == null ){
					
					return( null );
				}
				
				try{
					return( new String( res, "UTF8" ));
					
				}catch( Throwable e ){
					
					Debug.printStackTrace( e );
					
					return( null );
				}
			}

	   		if ( fixup()){
				
				return( delegate.getAdditionalStringProperty( name ));
			}
	   		
	   		return( null );
    	}
    		
    	public void
    	setAdditionalByteArrayProperty(
    		String		name,
    		byte[]		value )
       	{
	   		if ( fixup()){
				
				delegate.setAdditionalByteArrayProperty( name, value );
			}
    	}
    	
    	public byte[]
    	getAdditionalByteArrayProperty(
    		String		name )
       	{
	   		if ( fixup()){
				
				return( delegate.getAdditionalByteArrayProperty( name ));
			}
	   		
	   		return( null );
    	}
    	
    	public void
    	setAdditionalLongProperty(
    		String		name,
    		Long		value )
       	{
	   		if ( fixup()){
				
				delegate.setAdditionalLongProperty( name, value );
			}
    	}
    		
    	public Long
    	getAdditionalLongProperty(
    		String		name )
       	{
	   		if ( fixup()){
				
				return( delegate.getAdditionalLongProperty( name ));
			}
	   		
	   		return( null );
    	}
    		
    	
    	public void
    	setAdditionalListProperty(
    		String		name,
    		List		value )
       	{
	   		if ( fixup()){
				
				delegate.setAdditionalListProperty( name, value );
			}
    	}
    		
    	public List
    	getAdditionalListProperty(
    		String		name )
       	{
	   		if ( fixup()){
				
				return( delegate.getAdditionalListProperty( name ));
			}
	   		
	   		return( null );
    	}
    		
    	public void
    	setAdditionalMapProperty(
    		String		name,
    		Map			value )
       	{
	   		if ( fixup()){
				
				delegate.setAdditionalMapProperty( name, value );
			}
    	}
    		
    	public Map
    	getAdditionalMapProperty(
    		String		name )
       	{
			Map	c = cache;
			
			if ( c != null && name.equals( "attributes")){
								
				return((Map)c.get( name ));
			}
			
	   		if ( fixup()){
				
				return( delegate.getAdditionalMapProperty( name ));
			}
	   		
	   		return( null );
    	}
    	
    	public Object
    	getAdditionalProperty(
    		String		name )
       	{
	   		if ( fixup()){
				
				return( delegate.getAdditionalProperty( name ));
			}
	   		
	   		return( null );
    	}

    	public void
    	setAdditionalProperty(
    		String		name,
    		Object		value )
       	{
	   		if ( fixup()){
				
				delegate.setAdditionalProperty( name, value );
			}
    	}
    	
    	public void
    	removeAdditionalProperty(
    		String name )
       	{
	   		if ( fixup()){
				
				delegate.removeAdditionalProperty( name );
			}
    	}
    	
    	public void
    	removeAdditionalProperties()
       	{
	   		if ( fixup()){
				
				delegate.removeAdditionalProperties();
			}
    	}
    	
    	public void
    	serialiseToBEncodedFile(
    		File		file )
    		  
    		throws TOTorrentException
	   	{
	   		if ( fixup()){
				
				delegate.serialiseToBEncodedFile( file );
				
				return;
			}
	   		
	   		throw( fixup_failure );
    	}
    	
    	public Map
    	serialiseToMap()
    		  
    		throws TOTorrentException
	   	{
	   		if ( fixup()){
				
				return( delegate.serialiseToMap());
			}
	   		
	   		throw( fixup_failure );
    	}
    	
       public void
       serialiseToXMLFile(
    	   File		file )
    		  
    	   throws TOTorrentException
   	   	{
   	   		if ( fixup()){
   				
   				delegate.serialiseToXMLFile( file );
   				
   				return;
   			}
   	   		
   	   		throw( fixup_failure );
       	}

       public AEMonitor
       getMonitor()
      	{
	   		if ( fixup()){
				
				return( delegate.getMonitor());
			}
	   		
	   		return( null );
      	}

       public void
       print()
      	{
	   		if ( fixup()){
				
				delegate.print();
			}
      	}

     	/* (non-Javadoc)
     	 * @see org.gudy.azureus2.core3.logging.LogRelation#getLogRelationText()
     	 */
     	public String getRelationText() {
     		return "Torrent: '" + new String(getName()) + "'";  
     	}

     	/* (non-Javadoc)
     	 * @see org.gudy.azureus2.core3.logging.LogRelation#queryForClass(java.lang.Class)
     	 */
     	public Object[] getQueryableInterfaces() {
     		// yuck
     		try {
     			return new Object[] { AzureusCoreFactory.getSingleton()
     					.getGlobalManager().getDownloadManager(this) };
     		} catch (Exception e) {
     		}

     		return null;
     	}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -