public static java.lang.Object | uploadFile(com.sun.appserv.management.base.UploadDownloadMgr mgr, java.io.File theFile)Upload a file to the server and return an opaque identifier which server-side
code may use to identify and use the file. Uploading a file is typically done
prior to deploying it, but may be done for other purposes.
final FileInputStream input = new FileInputStream( theFile );
final long length = input.available();
final Object uploadID = mgr.initiateUpload( theFile.getName(), length );
try
{
final int chunkSize = 256 * 1024;
long remaining = length;
while ( remaining != 0 )
{
final int actual = remaining < chunkSize ? (int)remaining : chunkSize;
final byte[] bytes = new byte[ actual ];
final int num = input.read( bytes );
if ( num != actual )
{
throw new IOException();
}
mgr.uploadBytes( uploadID, bytes );
remaining -= actual;
}
}
finally
{
input.close();
}
return( uploadID );
|