gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:52:34 25 4
gpt4 key购买 nike

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

如何使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com