encode response with gzip
This commit is contained in:
parent
c52820b1ae
commit
793d05ebb1
|
@ -0,0 +1,25 @@
|
||||||
|
package org.bench4q.recorder.httpcapture.generator;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
public class ContentEncoder {
|
||||||
|
protected Logger logger = Logger.getLogger(ContentEncoder.class);
|
||||||
|
protected ContentEncoder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ContentEncoder createEncoder(String encodeType) {
|
||||||
|
if (encodeType == null) {
|
||||||
|
return new ContentEncoder();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (encodeType.equalsIgnoreCase("gzip")) {
|
||||||
|
return new GzipEncoder();
|
||||||
|
} else {
|
||||||
|
return new ContentEncoder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] encoderContent(byte[] content){
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package org.bench4q.recorder.httpcapture.generator;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
public class GzipEncoder extends ContentEncoder{
|
||||||
|
|
||||||
|
public byte[] encoderContent(byte[] content){
|
||||||
|
try {
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream);
|
||||||
|
|
||||||
|
gzipOutputStream.write(content, 0, content.length);
|
||||||
|
gzipOutputStream.finish();
|
||||||
|
|
||||||
|
gzipOutputStream.flush();
|
||||||
|
gzipOutputStream.close();
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("decodeContent", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue