webservice 服务端是C#写的,返回的数据是压缩DataSet后的byte[],客户端是JAVA的,请问在JAVA这边怎么解析这个byte[]?
我先解压byte[] , 再把这个解压后的byte[]转成对象时就报错了:
java.io.StreamCorruptedException: invalid stream header: 00010000
以下是解压后的byte[]转对象代码, ObjectInputStream ois = new ObjectInputStream (bis);报错
public static Object toObject(byte[] bytes) { Object obj = null; try { ByteArrayInputStream bis = new ByteArrayInputStream (bytes); ObjectInputStream ois = new ObjectInputStream (bis); obj = ois.readObject(); ois.close(); bis.close(); } catch (IOException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } return obj; }
以下是解压byte[] 的到原始byte[]的代码
public static byte[] decompressByteArray(byte[] bytes){ ByteArrayOutputStream baos = null; Inflater iflr = new Inflater(); iflr.setInput(bytes); baos = new ByteArrayOutputStream(); byte[] tmp = new byte[4*1024]; try{ while(!iflr.finished()){ int size = iflr.inflate(tmp); baos.write(tmp, 0, size); } } catch (Exception ex){ } finally { try{ if(baos != null) baos.close(); } catch(Exception ex){} } return baos.toByteArray(); }