FileDocCategorySizeDatePackage
Misc.javaAPI DocGlassfish v2 API3484Fri May 04 22:30:50 BST 2007com.sun.appserv.management.helper

Misc

public class Misc extends Object
Miscellaneous helper routines specific to AMX. These routines may be moved prior to the release of 9.0
since
AppServer 9.0

Fields Summary
Constructors Summary
private Misc()

Methods Summary
public static java.lang.ObjectuploadFile(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.

param
mgr an instance of UploadDownloadMgr, obtained via getDomainRoot().getUploadDownloadMgr()
param
theFile the file to upload
return
an upload ID

		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 );