FileDocCategorySizeDatePackage
TorrentDownloaderImpl.javaAPI DocAzureus 3.0.3.43707Wed Nov 30 22:28:34 GMT 2005org.gudy.azureus2.pluginsimpl.local.torrent

TorrentDownloaderImpl

public class TorrentDownloaderImpl extends Object implements TorrentDownloader
author
parg

Fields Summary
private static final LogIDs
LOGID
protected TorrentManagerImpl
manager
protected URL
url
protected ResourceDownloader
downloader
protected boolean
encoding_requested
protected String
requested_encoding
protected boolean
set_encoding
Constructors Summary
protected TorrentDownloaderImpl(TorrentManagerImpl _manager, URL _url)

	
	
	
				
								 
	
		manager		= _manager;
		url			= _url;
		
		downloader = ResourceDownloaderFactoryImpl.getSingleton().create( url );
	
protected TorrentDownloaderImpl(TorrentManagerImpl _manager, URL _url, String _user_name, String _password)

		manager	= _manager;
		url		= _url;
		
			// assumption here is that if we have a user name and password supplied
			// then user-interaction is NOT required. Thus we set the default encoding
			// to ensure that in the unlikely event of the torrent having multiple 
			// encodings the SWT UI isn't kicked off to get an encoding when the user
			// is absent.
		
		set_encoding	= true;
		
		downloader = ResourceDownloaderFactoryImpl.getSingleton().create( url, _user_name, _password );
		
		downloader.addListener(new ResourceDownloaderAdapter() {
			public void reportActivity(ResourceDownloader downloader, String activity) {
				if (Logger.isEnabled())
					Logger.log(new LogEvent(LOGID, "TorrentDownloader:" + activity));
			}
		});
		
	
Methods Summary
public Torrentdownload()

		InputStream	is = null;
		
		try{
			is = downloader.download();
			
			TOTorrent	torrent = TOTorrentFactory.deserialiseFromBEncodedInputStream(is);
			
			if ( encoding_requested ){
				
				manager.tryToSetTorrentEncoding( torrent, requested_encoding );
			}else{
				
				if ( set_encoding ){
					
					manager.tryToSetDefaultTorrentEncoding( torrent );
				}
			}
			
			return( new TorrentImpl(torrent ));
			
		}catch( TorrentException e ){
			
			throw( e );
			
		}catch( Throwable e ){
			
			throw( new TorrentException( "TorrentDownloader: download fails", e ));
			
		}finally{
			
			if ( is != null ){
				
				try{
					
					is.close();
					
				}catch( IOException e ){
					
					Debug.printStackTrace( e );
				}
			}
		}
	
public Torrentdownload(java.lang.String encoding)

		encoding_requested	= true;
		requested_encoding	= encoding;
		
		return( download());