FileDocCategorySizeDatePackage
ExternalSeedReaderRequest.javaAPI DocAzureus 3.0.3.44019Tue Aug 14 22:27:08 BST 2007com.aelitis.azureus.plugins.extseed.impl

ExternalSeedReaderRequest

public class ExternalSeedReaderRequest extends Object implements com.aelitis.azureus.plugins.extseed.util.ExternalSeedHTTPDownloaderListener

Fields Summary
private ExternalSeedReaderImpl
reader
private List
requests
private int
start_piece_number
private int
start_piece_offset
private int
length
private int
current_request_index
private org.gudy.azureus2.plugins.peers.PeerReadRequest
current_request
private byte[]
current_buffer
private int
current_position
Constructors Summary
protected ExternalSeedReaderRequest(ExternalSeedReaderImpl _reader, List _requests)

	
	 
	
			
							 
	
		reader		= _reader;
		requests	= _requests;
		
		for (int i=0;i<requests.size();i++){
			
			PeerReadRequest	req = (PeerReadRequest)requests.get(i);
			
			if ( i == 0 ){
				
				start_piece_number	= req.getPieceNumber();
				start_piece_offset	= req.getOffset();
			}
			
			length	+= req.getLength();
		}
	
Methods Summary
protected voidcancel()

		for (int i=0;i<requests.size();i++){
			
			PeerReadRequest	req = (PeerReadRequest)requests.get(i);

			if ( !req.isCancelled()){
				
				req.cancel();
			}
		}
	
public voiddone()

		reader.informComplete( current_request, current_buffer );
	
public voidfailed()

		for (int i=current_request_index;i<requests.size();i++){
			
			PeerReadRequest	request = (PeerReadRequest)requests.get(i);

			reader.informFailed( request );
		}
	
public byte[]getBuffer()

		if ( current_request_index >= requests.size()){
			
			throw( new ExternalSeedException( "Insufficient buffers to satisfy request" ));
		}
		
		current_request = (PeerReadRequest)requests.get(current_request_index++);
		
		current_buffer = new byte[ current_request.getLength()];
		
		current_position	= 0;
		
		return( current_buffer );
	
public intgetBufferLength()

		return( current_buffer.length );
	
public intgetBufferPosition()

		return( current_position );
	
public intgetLength()

		return( length );
	
public intgetPercentDoneOfCurrentIncomingRequest()

		PeerReadRequest	req = current_request;
		
		if ( req == null ){
			
			return( 0 );
		}
		
		return(( 100 * current_position ) / req.getLength() );
		
	
public intgetPermittedBytes()

		PeerReadRequest	req = current_request;
		
		if ( req == null ){
			
			req = (PeerReadRequest)requests.get(0);	
		}
		
		if ( req.isCancelled()){
			
			throw( new ExternalSeedException( "Request cancelled" ));
		}
		
		return( reader.getPermittedBytes());
	
public intgetStartPieceNumber()

		return( start_piece_number );
	
public intgetStartPieceOffset()

		return( start_piece_offset );
	
public voidreportBytesRead(int num)

		reader.reportBytesRead( num );
	
public voidsetBufferPosition(int pos)

		current_position	= pos;