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

标签 java android web-services zip ksoap2

我需要从网络服务中获取部分文件。网络服务让我分割文件。我作为参数发送(我需要的部分和字节大小)之前已经知道总共有多少部分及其各自的重量。

如何使用 KSOAP2 获取这些部件,然后创建 .zip

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

最佳答案

我选择了一个基本的解决方案:通过“for”向 ws 询问位和字节来连接和断开连接。鉴于要询问的最后一部分应该很好地计算(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

关于java - 如何使用 KSOAP2 从 Web 服务获取文件的一部分并创建 zip?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35677345/

相关文章:

android - Light.DarkActionBar 菜单项文本颜色不可更改?

web-services - 不同服务器上的 Web 服务之间的通信

javascript - "fake"跨域请求的Web服务?

c# - 如何使用 Delphi 2007 中的非 IIS 托管、WCF、C# Web 服务?

java - 如何为每个数组元素创建一个数组?

java - 如何在 Android 上使用 swi-prolog

java - 具有多个模式的 WSDL 的自定义解析和打印方法

java - "window inside window"与 Swing 和 Netbeans

android - 全高流体图像和 div 在一行中。 Div 必须占据剩余的水平空间

android - 带抽屉布局的 fragment 管理