开发者

GZip from a File that contains text data as well

开发者 https://www.devze.com 2023-04-12 04:53 出处:网络
We get a gzip file via MQ and this has some message properties appended to the stream as well. Can we read the gzip data from the stream and unzip it? If this is possible, please could you give some p

We get a gzip file via MQ and this has some message properties appended to the stream as well. Can we read the gzip data from the stream and unzip it? If this is possible, please could you give some pointers. Thank yo开发者_JS百科u.


read function return the actual number of bytes read. So you should store the return value of this function (currently inside while check in your code). When this value is != -1 and is < 1024 then it gives you the idea that where gzip data ends and string data starts.


This should work. My need tweaking (not tested).

Edit:

GZIPInputStream gz = new GZIPInputStream(inputStream);
InputStreamReader r = new InputStreamReader(gz);
BufferedReader br = new BufferedReader(r);
StringBuilder sb = new StringBuilder();
String line;
while ( (line = br.readLine()) != null ) {
    sb.append(line);
}
System.out.println(sb.toString());
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号