简体   繁体   English

如何使用KSOAP2从Web服务获取文件的一部分并创建zip?

[英]How to get parts of a file with KSOAP2 from webservice and create zip?

I need to get a file in parts from web service. 我需要从Web服务获取部分文件。 The web service gives me split the file. Web服务使我可以拆分文件。 I send as parameters (the part that I need and size of bytes) previously already know how many parts are in total and their respective weight. 我以前作为参数(我需要的部分和字节大小)发送的信息已经知道总共有多少部分及其各自的权重。

How I can get these parts with KSOAP2 and then create a .zip ? 如何使用KSOAP2获得这些部件,然后创建一个.zip

byte[] bytess = SomeDecode(MyMethodWS (10, 1024)); //example Part 10 of 15

I opted for a basic solution: connect and disconnect through a "for" asking bits and bytes to ws. 我选择了一个基本的解决方案:通过“ for”向ws请求位和字节来连接和断开连接。 Given that the last part to be asked should be well calculated (numberBytes). 鉴于要问的最后一部分应该得到很好的计算(numberBytes)。

FileOutputStream fos = new FileOutputStream(file,true); //Important that 'true'.

int numberBytes =  1024; //if numberBytes < 'sizefile' then = sizefile
int numberPart = 0; //

int parts = sizefile/numberBytes; // if the result is decimal must add +1

for(int b=0;b<parts;b++){

    //Calculate the part to be ordered: 0...numberBytes+1 ...n+1 ...n+1
    numberPart = functionCalculate(numberBytes,sizefile,b);

    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

    PropertyInfo p1 = new PropertyInfo();
    pi.setName("part");
    pi.setValue(numberPart);
    pi.setType(int.class);
    Request.addProperty(p1);

    PropertyInfo p2 = new PropertyInfo();
    p2.setName("bytess");
    p2.setValue(numberBytes);
    p2.setType(int.class);
    Request.addProperty(p2);

    Blah blah ksoap code…
    Blah blah ksoap code…

    try{

        Blah blah ksoap code…
        Blah blah ksoap code…

        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();                         
        bytes = response.toString().getBytes(“UTF-8”);                      
        fos.write(bytes,0,bytes.length);//It is a zip. no need to build a zip    
    }catch(...
}//end for

close fos

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM