FileDocCategorySizeDatePackage
DownloadInfo.javaAPI DocGlassfish v2 API4108Fri May 04 22:23:42 BST 2007com.sun.enterprise.management.support

DownloadInfo

public final class DownloadInfo extends UpDownInfo

Fields Summary
private FileInputStream
mInputStream
private long
mReadSoFar
private final long
mTotalSize
private final boolean
mDeleteWhenDone
Constructors Summary
public DownloadInfo(Object id, File theFile, boolean deleteWhenDone)

		super( id, theFile );
		
		mTotalSize		= theFile.length();
		if ( theFile.length() == 0 )
		{
			throw new IllegalArgumentException( theFile.toString() );
		}
		
		mReadSoFar		= 0;
		mDeleteWhenDone	= deleteWhenDone;
		
		if ( mDeleteWhenDone )
		{
			theFile.deleteOnExit();
		}
		
		mInputStream	= new FileInputStream( theFile );
		
		assert( ! isDone() );
	
Methods Summary
public synchronized voidcleanup()

		if ( mInputStream != null )
		{
			mInputStream.close();
			mInputStream	= null;
		}
		
		if ( mDeleteWhenDone )
		{
			getFile().delete();
		}
	
public final longgetLength()

		return( mTotalSize );
	
private final longgetRemaining()

		return( mTotalSize - mReadSoFar );
	
public booleanisDone()

		return( mReadSoFar == mTotalSize );
	
public synchronized byte[]read(int requestSize)

return
true if done, false otherwise

		if ( isDone() )
		{
			throw new IllegalArgumentException( "operation has been completed" );
		}
		
		final long	remaining	= getRemaining();
		
		byte[]		bytes	= null;
		if ( remaining != 0 )
		{
			final long	actual		= remaining < requestSize ? remaining : requestSize;
			
			bytes	= new byte[ (int)actual ];
			final int	numRead	= mInputStream.read( bytes );
			if ( numRead != bytes.length )
			{
				throw new IOException();
			}
			
			mReadSoFar	+= numRead;
			
			if ( isDone() )
			{
				cleanup();
			}
			
			accessed();
		}
		
		return( bytes );