1 23 package com.sun.appserv.management.helper; 24 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.io.IOException ; 28 29 import com.sun.appserv.management.base.UploadDownloadMgr; 30 31 36 public class Misc 37 { 38 private Misc() {} 39 40 50 public static Object 51 uploadFile( 52 final UploadDownloadMgr mgr, 53 final File theFile ) 54 throws IOException 55 { 56 final FileInputStream input = new FileInputStream ( theFile ); 57 final long length = input.available(); 58 final Object uploadID = mgr.initiateUpload( theFile.getName(), length ); 59 60 try 61 { 62 final int chunkSize = 256 * 1024; 63 long remaining = length; 64 while ( remaining != 0 ) 65 { 66 final int actual = remaining < chunkSize ? (int)remaining : chunkSize; 67 68 final byte[] bytes = new byte[ actual ]; 69 final int num = input.read( bytes ); 70 if ( num != actual ) 71 { 72 throw new IOException (); 73 } 74 75 mgr.uploadBytes( uploadID, bytes ); 76 remaining -= actual; 77 } 78 } 79 finally 80 { 81 input.close(); 82 } 83 84 return( uploadID ); 85 } 86 } 87 88 89 | Popular Tags |