FileDocCategorySizeDatePackage
CacheFileWithoutCache.javaAPI DocAzureus 3.0.3.47020Fri Mar 23 14:10:38 GMT 2007com.aelitis.azureus.core.diskmanager.cache.impl

CacheFileWithoutCache

public class CacheFileWithoutCache extends Object implements CacheFile
author
parg

Fields Summary
protected CacheFileManagerImpl
manager
protected com.aelitis.azureus.core.diskmanager.file.FMFile
file
protected org.gudy.azureus2.core3.torrent.TOTorrentFile
torrent_file
Constructors Summary
protected CacheFileWithoutCache(CacheFileManagerImpl _manager, com.aelitis.azureus.core.diskmanager.file.FMFile _file, org.gudy.azureus2.core3.torrent.TOTorrentFile _torrent_file)

		manager			= _manager;
		file			= _file;
		torrent_file	= _torrent_file;
		// System.out.println( "without cache = " + file.getFile().toString());
	
Methods Summary
public voidclearCache()

	
public voidclose()

		try{
			
			file.close();
			
		}catch( FMFileManagerException e ){
			
			manager.rethrow(this,e);			
		}
	
public longcompareLength(long compare_to)

		return( getLength() - compare_to );
	
public voiddelete()

		try{
			
			file.delete();
			
		}catch( FMFileManagerException e ){
			
			manager.rethrow(this,e);			
		}
	
public voidensureOpen(java.lang.String reason)

		try{
			
			file.ensureOpen( reason );
			
		}catch( FMFileManagerException e ){
			
			manager.rethrow(this,e);
		}	
	
public booleanexists()

		return( file.exists());
	
public voidflushCache()

		try{
			file.flush();
		
		}catch( FMFileManagerException e ){
		
			manager.rethrow(this,e);
		}
	
public intgetAccessMode()

		return( file.getAccessMode()==FMFile.FM_READ?CF_READ:CF_WRITE );
	
public longgetLength()

		try{
						
			return( file.getLength());
			
		}catch( FMFileManagerException e ){
			
			manager.rethrow(this,e);
			
			return( 0 );
		}
	
public intgetStorageType()

		return( file.getStorageType()==FMFile.FT_COMPACT?CT_COMPACT:CT_LINEAR );
	
public org.gudy.azureus2.core3.torrent.TOTorrentFilegetTorrentFile()

		return( torrent_file );
	
public booleanisOpen()

		return( file.isOpen());
	
public voidmoveFile(java.io.File new_file)

		try{
			file.moveFile( new_file );
			
		}catch( FMFileManagerException e ){
			
			manager.rethrow(this,e);
		}	
	
public voidread(org.gudy.azureus2.core3.util.DirectByteBuffer[] buffers, long position, short policy)

		int	read_length	= 0;
		
		for (int i=0;i<buffers.length;i++){
			
			read_length += buffers[i].remaining(DirectByteBuffer.SS_CACHE);
		}
		
		try{			
			file.read( buffers, position );
			
			manager.fileBytesRead( read_length );

		}catch( FMFileManagerException e ){
				
			manager.rethrow(this,e);
		}
	
public voidread(org.gudy.azureus2.core3.util.DirectByteBuffer buffer, long position, short policy)

		int	read_length	= buffer.remaining(DirectByteBuffer.SS_CACHE);

		try{			
			file.read( buffer, position );
			
			manager.fileBytesRead( read_length );

		}catch( FMFileManagerException e ){
				
			manager.rethrow(this,e);
		}
	
public voidsetAccessMode(int mode)

		try{
			
			file.setAccessMode( mode==CF_READ?FMFile.FM_READ:FMFile.FM_WRITE );
			
		}catch( FMFileManagerException e ){
			
			manager.rethrow(this,e);
		}	
	
public voidsetLength(long length)

		try{
						
			file.setLength( length );
			
		}catch( FMFileManagerException e ){
			
			manager.rethrow(this,e);
		}
	
public voidsetStorageType(int type)

		try{
			
			file.setStorageType( type==CT_COMPACT?FMFile.FT_COMPACT:FMFile.FT_LINEAR );
			
		}catch( FMFileManagerException e ){
			
			manager.rethrow(this,e);
		}			
	
public voidwrite(org.gudy.azureus2.core3.util.DirectByteBuffer buffer, long position)

		int	write_length = buffer.remaining(DirectByteBuffer.SS_CACHE);
		
		try{			
			file.write( buffer, position );
			
			manager.fileBytesWritten( write_length );

		}catch( FMFileManagerException e ){
				
			manager.rethrow(this,e);
		}
	
public voidwrite(org.gudy.azureus2.core3.util.DirectByteBuffer[] buffers, long position)

		int	write_length	= 0;
		
		for (int i=0;i<buffers.length;i++){
			
			write_length += buffers[i].remaining(DirectByteBuffer.SS_CACHE);
		}
		
		try{			
			file.write( buffers, position );
			
			manager.fileBytesWritten( write_length );

		}catch( FMFileManagerException e ){
				
			manager.rethrow(this,e);
		}
	
public voidwriteAndHandoverBuffer(org.gudy.azureus2.core3.util.DirectByteBuffer buffer, long position)

		int	write_length = buffer.remaining(DirectByteBuffer.SS_CACHE);
		
		boolean	write_ok	= false;
		
		try{			
			file.write( buffer, position );
			
			manager.fileBytesWritten( write_length );

			write_ok	= true;
			
		}catch( FMFileManagerException e ){
				
			manager.rethrow(this,e);
			
		}finally{
			
			if ( write_ok ){
				
				buffer.returnToPool();
			}
		}
	
public voidwriteAndHandoverBuffers(org.gudy.azureus2.core3.util.DirectByteBuffer[] buffers, long position)

		int	write_length	= 0;
		
		for (int i=0;i<buffers.length;i++){
			
			write_length += buffers[i].remaining(DirectByteBuffer.SS_CACHE);
		}
		
		boolean	write_ok	= false;
		
		try{			
			file.write( buffers, position );
			
			manager.fileBytesWritten( write_length );

			write_ok	= true;
			
		}catch( FMFileManagerException e ){
				
			manager.rethrow(this,e);
			
		}finally{
			
			if ( write_ok ){
				
				for (int i=0;i<buffers.length;i++){

					buffers[i].returnToPool();
				}
			}
		}