在java中读取压缩或压缩的响应数据

时间:2017-02-02 04:18:26

标签: java spring performance servlets httpresponse

我正在尝试从java中的responsedata读取数据。数据是在响应机构中设置的。但是如何从代码中的响应中读取数据。

The below code is for used for setting the compressed or zipped the data. The objective is to read this response data into string. 

writeBytes(byte[] responseData, HttpServletRequest request, HttpServletResponse response, String contentType) throws IOException {
.......some code 
.......some code

ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
    response.setHeader("Content-Encoding", "gzip");
    byte[] responseData;
    responseData = GzipHelper.compressGZIP(responseData);
    int contentLength1 = contentBytes.size();

response.setContentLength(contentLength1);
contentBytes.writeTo(response.getOutputStream());
}

Where 
public static byte[] compressGZIP(byte[] data1) throws IOException {
ByteArrayOutputStream os1 = new ByteArrayOutputStream();
GZIPOutputStream gzipp = new GZIPOutputStream(os1);
byte[] arg;
try {
gzipp.write(data1);
gzipp.finish();
arg = os1.toByteArray();
} finally {
    }

///////////

Now I have to read this zipped or compressed data. I can see that when I check value of response.getoutputstream() it is showing me data in some encrypted format. But how can I  unzipped or uncompressed response data and convert it into more meaningful response or in readable string? The objective is to read actual response body data (real body) that has been set.     Please advice. 

0 个答案:

没有答案