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

ByteChunk

public class ByteChunk extends Object implements Serializable
A Class that represents a Chunk of Bytes. This is designed to be used to transfer bytes of data between remote entities. There are some properties of the class that will allow users of this class to take specific actions. Maximum size of the chunk is 64 KBytes. Needs to be Serializable, for ByteChunks may transmit over wire.

Chunks are generally parts of file identified by a name. Note that this class is modeled to be immutable.

author
Kedar Mhaswade
version
1.0

Fields Summary
public static final long
serialVersionUID
public static final int
kChunkMaxSize
public static final int
kChunkMinSize
private int
mSize
private boolean
mIsLast
private boolean
mIsFirst
private byte[]
mBytes
private String
mChunkedFileName
private String
mTargetDir
private String
mUniqueId
private long
mTotalFileSize
Constructors Summary
public ByteChunk(byte[] byteArray, String forFileName, boolean isFirst, boolean isLast, String uniqueId, long totalFileSize)
Creates new ByteChunk with the specified size. The chunk may not be larger than the size specfied by kChunkMaxSize.

throws
IllegalArgumentException if the size of Chunk is more than kChunkSize or less than kChunkMinSize..
param
byteArray specifies the array of bytes that constitutes chunk.
param
forFileName specifies the name of the file whose part is it.
param
isFirst boolean specifying if this is the first of the chunks.
param
isLast boolean specifying if this is the first of the chunks.
param
uniqueId String specifies an unique id for this series of chunks. This has to be same in all chunks of the series.
param
totalFileSize long specifies total file size of the chunked file.


	                                                                       	 		         		           		           		           		                                               		              
	
         
               
    
        int size =0;
        if (byteArray != null) {
            size = byteArray.length;
            if ( size < kChunkMinSize || size > kChunkMaxSize)
            {
                throw new IllegalArgumentException(size + "");
            }
        }
        mSize               = size;
        mIsFirst            = isFirst;
        mIsLast             = isLast;
        mBytes              = byteArray;
        mChunkedFileName    = forFileName;
        mUniqueId           = uniqueId;
        mTotalFileSize      = totalFileSize;
    
public ByteChunk(byte[] byteArray, String forFileName, boolean isFirst, boolean isLast)
Creates new ByteChunk with the specified size. The chunk may not be larger than the size specfied by kChunkMaxSize.

throws
IllegalArgumentException if the size of Chunk is more than kChunkSize or less than kChunkMinSize..
param
byteArray specifies the array of bytes that constitutes chunk.
param
forFileName specifies the name of the file whose part is it.
param
isFirst boolean specifying if this is the first of the chunks.
param
isLast boolean specifying if this is the first of the chunks.

        this(byteArray,forFileName,isFirst,isLast,forFileName, -1);
    
Methods Summary
public byte[]getBytes()
Gets the array of actual bytes.

return
byte[] with actual bytes.

        return mBytes;
    
public java.lang.StringgetChunkedFileName()
Returns the name of the file that was chunked.

return
String representing the name of file (whose this is a chunk).

        return ( mChunkedFileName );
    
public java.lang.StringgetId()
Returns the unique id for this series of chunks.

        return mUniqueId;
    
public intgetSize()
Gets the actual size of the chunk. The chunk will have exactly this many bytes in the underlying byte array.

return
integer indicating the size of the chunk.

        return ( mSize );
    
public java.lang.StringgetTargetDir()
Returns the name of the target directory to which this chunk is copied.

        return ( mTargetDir );
    
public longgetTotalFileSize()
returns the total file size.

        return mTotalFileSize;
    
public booleanisFirst()
Determines whether this is the last Chunk in a series of Chunk transfer.

return
true if this is last Chunk, false otherwize.

        return ( mIsFirst );
    
public booleanisLast()
Determines whether this is the last Chunk in a series of Chunk transfer.

return
true if this is last Chunk, false otherwize.

        return ( mIsLast );
    
public voidsetTargetDir(java.lang.String targetDir)
Sets the target dir to which this chunk must be copied.

        mTargetDir = targetDir;