FileDocCategorySizeDatePackage
ResourceDownloaderFileImpl.javaAPI DocAzureus 3.0.3.44752Thu May 24 06:59:36 BST 2007org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader

ResourceDownloaderFileImpl

public class ResourceDownloaderFileImpl extends ResourceDownloaderBaseImpl
author
parg

Fields Summary
protected boolean
cancelled
protected File
file
protected Object
result
protected org.gudy.azureus2.core3.util.AESemaphore
done_sem
protected long
size
Constructors Summary
public ResourceDownloaderFileImpl(ResourceDownloaderBaseImpl _parent, File _file)

	
	
	
			
								 
	
		super( _parent );
		
		file		= _file;
	
Methods Summary
public voidasyncDownload()

		
		try{
			this_mon.enter();
		
			if ( !cancelled ){
								
				informActivity( getLogIndent() + ( file.isDirectory()?"Processing: ":"Downloading: " ) + getName());
				
				Thread t = new AEThread( "ResourceDownloaderTimeout")
					{
						public void
						runSupport()
						{
							try{
								
									// download of a local dir -> null inputstream
								
								if ( file.isDirectory()){
									
									completed( ResourceDownloaderFileImpl.this, null );

								}else{
								
									completed( ResourceDownloaderFileImpl.this, new FileInputStream( file ));
								}
								
							}catch( Throwable e ){
								
								failed( ResourceDownloaderFileImpl.this, new ResourceDownloaderException( "Failed to read file", e ));
								
								Debug.printStackTrace( e );
							}
						}
					};
				
				t.setDaemon(true);
		
				t.start();
			}
		}finally{
			
			this_mon.exit();
		}
	
protected voidcancel(org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloaderException reason)

		setCancelled();
		
		try{
			this_mon.enter();
		
			result	= reason; 
			
			cancelled	= true;
		
			informFailed((ResourceDownloaderException)result );
			
		}finally{
			
			this_mon.exit();
		}
	
public voidcancel()

		cancel( new ResourceDownloaderException( "Download cancelled"));
	
public booleancompleted(org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloader downloader, java.io.InputStream data)

		if (informComplete( data )){
			
			result	= data;
			
			done_sem.release();
			
			return( true );
		}
		
		return( false );
	
public java.io.InputStreamdownload()

		asyncDownload();
		
		done_sem.reserve();
		
		if ( result instanceof ResourceDownloaderException ){
			
			throw((ResourceDownloaderException)result);
		}
		
		return((InputStream)result);	
	
public voidfailed(org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloader downloader, org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloaderException e)

		result		= e;
		
		done_sem.release();
		
		informFailed( e );
	
public ResourceDownloaderBaseImplgetClone(ResourceDownloaderBaseImpl parent)

		ResourceDownloaderFileImpl c = new ResourceDownloaderFileImpl( getParent(), file );
				
		return( c );
	
public java.lang.StringgetName()

		return( file.toString());
	
public longgetSize()

	
		String	file_str = file.toString();
		
		int	pos = file_str.lastIndexOf( "." );
		
		String	file_type;
		
		if ( pos != -1 ){
		
			file_type = file_str.substring(pos+1);
			
		}else{
			
			file_type = null;
		}
		
		setProperty( 	ResourceDownloader.PR_STRING_CONTENT_TYPE,
						HTTPUtils.guessContentTypeFromFileType( file_type ));
		
		return( FileUtil.getFileOrDirectorySize( file ));
	
protected voidsetProperty(java.lang.String name, java.lang.Object value)

		setPropertySupport( name, value );
	
protected voidsetSize(long size)