2016-02-28 20 views
1

我需要從Web服務中獲取部分文件。 Web服務讓我分割文件。我發送的參數(我需要的部分和字節大小)以前已經知道總共有多少部分以及它們各自的權重。如何從webservice中使用KSOAP2獲取文件的部分並創建zip?

我怎樣可以得到KSOAP2這些零部件,然後創建一個.ZIP

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

回答

0

我選擇了一個基本的解決方案:通過「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 
相關問題