首页 新闻 赞助 找找看

java调用.net的webservice服务端

0
悬赏园豆:120 [待解决问题]

用java 调用webservice服务端 ,返回的是DataSetSurrogate对象用Binary 序列化并Zip压缩后的字节数组,这个字节数组该怎么解析呢~~请求各位指点~~

wangxg的主页 wangxg | 初学一级 | 园豆:82
提问于:2018-05-17 13:41
< >
分享
所有回答(2)
1

a+1=b;

那么a=b-1;

你既然都知道怎么正向处理到结果,反向一下不就行了。

花飘水流兮 | 园豆:13560 (专家六级) | 2018-05-18 00:12

嗯,思路是将获取到的byte数组先zip解压,然后反序列化成一个object对象,网上找了些解压byte[] 的代码,执行时一直报空指针错误,解压不成功~

public static byte[] unZip(byte[] data) {  
byte[] b = null;  
try {  
ByteArrayInputStream bis = new ByteArrayInputStream(data);  
ZipInputStream zip = new ZipInputStream(bis);  
while (zip.getNextEntry() != null) {  //zip.getNextEntry()这一步一直报空指针异常执行不下去
byte[] buf = new byte[1024];  
int num = -1;  
ByteArrayOutputStream baos = new ByteArrayOutputStream();  
while ((num = zip.read(buf, 0, buf.length)) != -1) {  
baos.write(buf, 0, num);  
}  
b = baos.toByteArray();  
baos.flush();  
baos.close();  
}  
zip.close();  
bis.close();  
} catch (Exception ex) {  
ex.printStackTrace();  
}  
return b;  
}  

 

支持(0) 反对(0) wangxg | 园豆:82 (初学一级) | 2018-05-18 09:38
0


    public static byte[] releaseCompression(byte[] bytesArray) throws IOException{
         
        ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bytesArray));
 
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
         
        ZipEntry ze  = null;
         
        while((ze = zis.getNextEntry()) != null){
                 
            int fileSize = (int) ze.getSize();
                 
            byte[] b = new byte[fileSize];    
            int rb = 0, chunk = 0;
             
         
            while(fileSize - rb > 0)
            {   
                chunk = zis.read(b, rb, fileSize - rb);
                if (chunk <= 0) 
                {
                    break;
                }
                rb += chunk;
            }
             
            bos.write(b);
            zis.close();
            break;
        }
         
        return bos.toByteArray();
    }

可以试试,最好debug调试看看数据

jingxunch | 园豆:221 (菜鸟二级) | 2018-05-22 17:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册