Java Axis2文件按块上载

Java Axis2文件按块上载,java,web-services,axis2,java-io,Java,Web Services,Axis2,Java Io,我正在尝试使用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,tr

我正在尝试使用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();
        }
}
我的客户端如下所示:

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到400k之间变化

我做错了什么

更新:我查看了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异常

尝试添加
fos.flush()
fos.close()之前在服务器实现中

改变

while((count = fis.read(buffer, 0, CHUNK_SIZE)) >0 )
为了


您使用Web服务来实现这一点有什么具体原因吗?这将有非常高的开销,因为您的数据在嵌入xml之前将转换为base64,每个数据块可能还将使用一个新的TCP连接。为什么不使用一个简单的http post请求来代替servlet呢?嗨,不幸的是,这是有原因的,我有一个第三方客户机,它以这种方式上传二进制数据:(而且我必须编写与此客户机兼容的Web服务。我知道所有SOAP头都会有性能问题,但老实说,我不在乎。