FileDocCategorySizeDatePackage
DownloadRequestInfo.javaAPI DocGlassfish v2 API6399Fri May 04 22:33:16 BST 2007com.sun.enterprise.admin.common

DownloadRequestInfo

public class DownloadRequestInfo extends Object implements Serializable
Contains information pertaining to a download request.

NOT THREAD SAFE: mutable instance variables

author
Nazrul Islam
since
J2SE1.4

Fields Summary
private String
_downloadFilePath
private int
_numChunks
private long
_numBytesSent
private boolean
_isPrepared
private int
_chunkIndex
private ByteChunk
_chunk
private long
_totalFileSize
Constructors Summary
private DownloadRequestInfo()
Constructor.

        _downloadFilePath    = null;
        _numChunks           = 0;
        _numBytesSent        = 0;
        _isPrepared          = false;
        _chunkIndex          = -1;
        _chunk               = null;
    
public DownloadRequestInfo(File f)

        super();

        if (f.exists()) {
            _downloadFilePath = f.getAbsolutePath();

            // total size of the download file
            _totalFileSize   = f.length();

            // total number of chunks
            _numChunks  = (int)(_totalFileSize/ (long)ByteChunk.kChunkMaxSize);

            // verifies the total
            if (_numChunks * (long)ByteChunk.kChunkMaxSize < _totalFileSize) {
                _numChunks += 1;
            }

            // sets the prepared flag
            _isPrepared = true;
            _chunkIndex = 0;
        }
    
Methods Summary
public ByteChunkgetChunk()
Returns the byte chunk for this request.

return
byte chunk

        return _chunk;
    
public intgetChunkIndex()
Returns the current chunk index.

return
the current chunk index

        return _chunkIndex;
    
public java.lang.StringgetDownloadFilePath()
Returns the download file path.

return
download file path

        return _downloadFilePath;
    
public longgetNumberOfBytesSent()
Returns the total number of bytes downloaded.

return
total number of bytes downloaded

        return _numBytesSent;
    
public intgetNumberOfChunks()
Returns total number of download chunks for this request.

return
total number of download chunks

        return _numChunks;
    
public longgetTotalFileSize()
Returns the total file size for this request.

return
total file size

        return _totalFileSize;
    
public voidincrementNumberOfBytesSent(int bytesRead)
Increments the total number of bytes sent out.

param
bytesRead number of bytes to be added to the total

        _numBytesSent += bytesRead;
    
public booleanisFirstChunk()
Returns true if this is the first chunk to download.

return
true if this is the first chunk

        return (_chunkIndex == 0);
    
public booleanisLastChunk()
Returns true if this the last chunk to download.

return
true if this the last chunk.

        return (_chunkIndex == (_numChunks-1));
    
public booleanisPrepared()
Returns true if the request info is computed

return
if the request is prepared

        return _isPrepared;
    
public voidsetChunk(ByteChunk chunk)
Sets the byte chunk for this request.

param
chunk byte chunk

        _chunk = chunk;
    
voidsetChunkIndex(int i)
Sets the current chunk index.

param
i current chunk index

        _chunkIndex = i;

        // resets the byte chunk
        _chunk      = null;
    
voidsetDownloadFilePath(java.lang.String f)
Sets the download file path.

param
f download file path

        _downloadFilePath = f;
    
voidsetNumberOfChunks(int n)
Sets the total number of download chunks.

param
n total number of download chunks

        _numChunks = n;
    
voidsetPrepared(boolean p)
Sets the prepared flag for this request.

param
p prepared flag for this request.

        _isPrepared = p;