用java 调用webservice服务端 ,返回的是DataSetSurrogate对象用Binary 序列化并Zip压缩后的字节数组,这个字节数组该怎么解析呢~~请求各位指点~~
a+1=b;
那么a=b-1;
你既然都知道怎么正向处理到结果,反向一下不就行了。
嗯,思路是将获取到的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; }
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调试看看数据