开发者

GZip from a File that contains text data as well

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜