Download Axis2 by chunk file

I am trying to upload a file using the Axis2 web service in size of 1024 pieces.

My server side is as follows:

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 is as follows:

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 that, the file size is incorrect, and if the file size of the original is 500 KB, the size of the original varies from 200 to 400 thousand.

What am I doing wrong?

Update: I looked at the log4j file in Tomcat

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 seems that all requests to the web server are executed asynchronously, and I also get an IO exception that the file is being used by another process.

+3
source share
1 answer

fos.flush(); fos.close(); .

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

while((count = fis.read(buffer, 0, CHUNK_SIZE)) != -1 )
+1

Source: https://habr.com/ru/post/1775408/


All Articles