Axis2 Web サービスを使用して 1024 チャンク サイズでファイルをアップロードしようとしています。
私のサーバー側は次のようになります。
public void appendChunk(int count, byte[] buffer){
FileOutputStream fos = null;
try {
File destinationFile = new File("c:\\file1.exe");
fos = new FileOutputStream(destinationFile,true);
fos.write(buffer,0, count);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally{
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
私のクライアント側は次のようになります。
static int CHUNK_SIZE =1024;
public static void main(String[] args) throws IOException, ServiceException {
FileUploadService strub = new FileUploadServiceLocator();
FileUploadServicePortType a = strub.getFileUploadServiceHttpSoap12Endpoint();
byte[] buffer = new byte[CHUNK_SIZE];
FileInputStream fis = null;
File file = new File("C:\\install.exe");
int count;
try {
fis = new FileInputStream(file);
while((count = fis.read(buffer, 0, CHUNK_SIZE)) >0 )
{
a.appendChunk(count, buffer);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
finally{
fis.close();
}
}
その後、ファイル サイズが正しくなく、元のファイル サイズが 500 KB の場合、元のサイズは 200 ~ 400 k の間で変動します。
私は何を間違っていますか?
更新: Tomcat の log4j ファイルを見ました
Nov 17, 2010 2:08:31 PM org.apache.tomcat.util.net.JIoEndpoint createWorkerThread
INFO: Maximum number of threads (200) created for connector with address null and port 80
Web サーバーへのすべての要求が非同期的に行われ、ファイルが別のプロセスによって使用されているという IO 例外も発生しているようです。