[英]Axis2 File Upload by chunk
I'm trying to upload file using Axis2 web service by 1024 chunk size. 我正在尝试使用Axis2 Web服务上传1024个块大小的文件。
My server side looks like this: 我的服务器端看起来像这样:
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();
}
}
}
my client side looks like this: 我的客户端看起来像这样:
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();
}
}
After it the file size is incorrect and if origina file size is 500 Kb, the original size varies between 200 and 400k. 之后文件大小不正确,如果原始文件大小为500 Kb,原始大小在200到400k之间变化。
What am I doing wrong? 我究竟做错了什么?
Update: I looked at log4j file in Tomcat 更新:我查看了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
It looks like all requests to the web server are done Asynchronously and and I also getting IO exception that the file is used by another process. 看起来所有对Web服务器的请求都是异步完成的,并且我也得到IO异常,该文件被另一个进程使用。
try to add fos.flush();
尝试添加
fos.flush();
before your fos.close();
在你的
fos.close();
之前fos.close();
in your server implementation. 在您的服务器实现中。
Change 更改
while((count = fis.read(buffer, 0, CHUNK_SIZE)) >0 )
for 对于
while((count = fis.read(buffer, 0, CHUNK_SIZE)) != -1 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.