use of java.util.zip.GZIPInputStream in project zipkin by openzipkin.
the class ZipkinHttpCollector method gunzip.
static byte[] gunzip(byte[] input) throws IOException {
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(input));
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(input.length)) {
byte[] buf = GZIP_BUFFER.get();
int len;
while ((len = in.read(buf)) > 0) {
outputStream.write(buf, 0, len);
}
return outputStream.toByteArray();
}
}
use of java.util.zip.GZIPInputStream in project jodd by oblac.
the class ZipUtil method ungzip.
/**
* Decompress gzip archive.
*/
public static File ungzip(File file) throws IOException {
String outFileName = FileNameUtil.removeExtension(file.getAbsolutePath());
File out = new File(outFileName);
out.createNewFile();
FileOutputStream fos = new FileOutputStream(out);
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(file));
try {
StreamUtil.copy(gzis, fos);
} finally {
StreamUtil.close(fos);
StreamUtil.close(gzis);
}
return out;
}
use of java.util.zip.GZIPInputStream in project nutz by nutzam.
the class Sender method createResponse.
protected Response createResponse(Map<String, String> reHeaders) throws IOException {
Response rep = null;
if (reHeaders != null) {
rep = new Response(conn, reHeaders);
if (rep.isOK()) {
InputStream is1 = conn.getInputStream();
InputStream is2 = null;
String encoding = conn.getContentEncoding();
// 如果采用了压缩,则需要处理否则都是乱码
if (encoding != null && encoding.contains("gzip")) {
is2 = new GZIPInputStream(is1);
} else if (encoding != null && encoding.contains("deflate")) {
is2 = new InflaterInputStream(is1, new Inflater(true));
} else {
is2 = is1;
}
BufferedInputStream is = new BufferedInputStream(is2);
rep.setStream(is);
} else {
try {
rep.setStream(conn.getInputStream());
} catch (IOException e) {
try {
rep.setStream(conn.getErrorStream());
} catch (Exception e1) {
rep.setStream(new VoidInputStream());
}
}
}
}
if (this.interceptor != null)
this.interceptor.afterResponse(request, conn, rep);
return rep;
}
use of java.util.zip.GZIPInputStream in project jodd by oblac.
the class HttpResponse method unzip.
// ---------------------------------------------------------------- body
/**
* Unzips GZip-ed body content, removes the content-encoding header
* and sets the new content-length value.
*/
public HttpResponse unzip() {
String contentEncoding = contentEncoding();
if (contentEncoding != null && contentEncoding().equals("gzip")) {
if (body != null) {
removeHeader(HEADER_CONTENT_ENCODING);
try {
ByteArrayInputStream in = new ByteArrayInputStream(body.getBytes(StringPool.ISO_8859_1));
GZIPInputStream gzipInputStream = new GZIPInputStream(in);
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamUtil.copy(gzipInputStream, out);
body(out.toString(StringPool.ISO_8859_1));
} catch (IOException ioex) {
throw new HttpException(ioex);
}
}
}
return this;
}
use of java.util.zip.GZIPInputStream in project openhab1-addons by openhab.
the class IhcClient method LoadProjectFileFromController.
private Document LoadProjectFileFromController() throws IhcExecption {
try {
WSProjectInfo projectInfo = getProjectInfo();
int numberOfSegments = controllerService.getProjectNumberOfSegments();
int segmentationSize = controllerService.getProjectSegmentationSize();
logger.debug("Number of segments: {}", numberOfSegments);
logger.debug("Segmentation size: {}", segmentationSize);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
for (int i = 0; i < numberOfSegments; i++) {
logger.debug("Downloading segment {}", i);
WSFile data = controllerService.getProjectSegment(i, projectInfo.getProjectMajorRevision(), projectInfo.getProjectMinorRevision());
byteStream.write(data.getData());
}
logger.debug("File size before base64 encoding: {} bytes", byteStream.size());
byte[] decodedBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(byteStream.toString());
logger.debug("File size after base64 encoding: {} bytes", decodedBytes.length);
GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(decodedBytes));
InputStreamReader in = new InputStreamReader(gzis, "ISO-8859-1");
InputSource reader = new InputSource(in);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
return db.parse(reader);
} catch (Exception e) {
throw new IhcExecption(e);
}
}
Aggregations