List of usage examples for java.util.zip GZIPInputStream GZIPInputStream
public GZIPInputStream(InputStream in) throws IOException
From source file:Main.java
public static byte[] gzipDecompress(byte[] input) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try {//w ww . jav a 2s. c o m GZIPInputStream is = new GZIPInputStream(new ByteArrayInputStream(input)); copy(is, out); } catch (IOException e) { throw new RuntimeException(e); } return out.toByteArray(); }
From source file:net.es.nsi.common.util.ContentType.java
public static String decode2String(String contentType, InputStream is) throws IOException { if (XGZIP.equalsIgnoreCase(contentType)) { return IOUtils.toString(new GZIPInputStream(is), Charset.defaultCharset()); } else {//from w w w. j a va 2 s.c om return IOUtils.toString(is, Charset.defaultCharset()); } }
From source file:Main.java
public static byte[] decompress(byte[] compressed) throws IOException { if (compressed == null || compressed.length == 0) { return compressed; }//from www . j av a 2s .c om ByteArrayInputStream sourceStream = new ByteArrayInputStream(compressed); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(compressed.length * 2); try (GZIPInputStream compressor = new GZIPInputStream(sourceStream)) { ByteStreams.copy(compressor, outputStream); compressor.close(); } try { return outputStream.toByteArray(); } finally { sourceStream.close(); outputStream.close(); } }
From source file:net.es.nsi.pce.util.ContentType.java
public static String decode2String(String contentType, InputStream is) throws IOException { if (XGZIP.equalsIgnoreCase(contentType)) { return IOUtils.toString(new GZIPInputStream(is)); } else {/*from ww w . java 2 s . c o m*/ return IOUtils.toString(is); } }
From source file:org.myframe.http.HttpUtils.java
public static byte[] responseToBytes(HttpResponse response) throws IOException, KJHttpException { HttpEntity entity = response.getEntity(); PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(ByteArrayPool.get(), (int) entity.getContentLength()); byte[] buffer = null; try {//from w w w . jav a 2s . c o m InputStream in = entity.getContent(); if (isGzipContent(response) && !(in instanceof GZIPInputStream)) { in = new GZIPInputStream(in); } if (in == null) { throw new KJHttpException("?"); } buffer = ByteArrayPool.get().getBuf(1024); int count; while ((count = in.read(buffer)) != -1) { bytes.write(buffer, 0, count); } return bytes.toByteArray(); } finally { try { // Close the InputStream and release the resources by // "consuming the content". entity.consumeContent(); } catch (IOException e) { // This can happen if there was an exception above that left the // entity in // an invalid state. MLoger.debug("Error occured when calling consumingContent"); } ByteArrayPool.get().returnBuf(buffer); bytes.close(); } }
From source file:com.scut.easyfe.network.kjFrame.http.HttpUtils.java
public static byte[] responseToBytes(HttpResponse response) throws IOException, KJHttpException { HttpEntity entity = response.getEntity(); PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(ByteArrayPool.get(), (int) entity.getContentLength()); byte[] buffer = null; try {/*from w w w. ja va2s. c om*/ InputStream in = entity.getContent(); if (isGzipContent(response) && !(in instanceof GZIPInputStream)) { in = new GZIPInputStream(in); } if (in == null) { throw new KJHttpException("?"); } buffer = ByteArrayPool.get().getBuf(1024); int count; while ((count = in.read(buffer)) != -1) { bytes.write(buffer, 0, count); } return bytes.toByteArray(); } finally { try { // Close the InputStream and release the resources by // "consuming the content". entity.consumeContent(); } catch (IOException e) { // This can happen if there was an exception above that left the // entity in // an invalid state. KJLoger.debug("Error occured when calling consumingContent"); } ByteArrayPool.get().returnBuf(buffer); bytes.close(); } }
From source file:com.eviware.soapui.impl.wsdl.support.CompressedStringSupport.java
public static String getString(CompressedStringConfig compressedStringConfig) { synchronized (compressedStringConfig) { String compression = compressedStringConfig.getCompression(); if ("gzip".equals(compression)) { try { byte[] bytes = Base64.decodeBase64(compressedStringConfig.getStringValue().getBytes()); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(bytes)); return Tools.readAll(in, -1).toString(); } catch (IOException e) { SoapUI.logError(e);/*from ww w. j a v a 2 s .c o m*/ } } return compressedStringConfig.getStringValue(); } }
From source file:com.boundary.zoocreeper.Restore.java
public static void main(String[] args) throws IOException, InterruptedException, KeeperException { RestoreOptions options = new RestoreOptions(); CmdLineParser parser = new CmdLineParser(options); try {/*from ww w . j a v a 2 s. c o m*/ parser.parseArgument(args); if (options.help) { usage(parser, 0); } } catch (CmdLineException e) { if (!options.help) { System.err.println(e.getLocalizedMessage()); } usage(parser, options.help ? 0 : 1); } if (options.verbose) { LoggingUtils.enableDebugLogging(Restore.class.getPackage().getName()); } InputStream is = null; try { if ("-".equals(options.inputFile)) { LOGGER.info("Restoring from stdin"); is = new BufferedInputStream(System.in); } else { is = new BufferedInputStream(new FileInputStream(options.inputFile)); } if (options.compress) { is = new GZIPInputStream(is); } Restore restore = new Restore(options); restore.restore(is); } finally { Closeables.close(is, true); } }
From source file:net.es.nsi.topology.translator.http.Decoder.java
private static byte[] gunzip(ByteArrayInputStream is) throws IOException { try (GZIPInputStream gis = new GZIPInputStream(is)) { return IOUtils.toByteArray(gis); } catch (IOException io) { log.error("Failed to gunzip document", io); throw io; }/*from w w w . j a v a2 s.c om*/ }
From source file:fr.dutra.confluence2wordpress.util.CodecUtils.java
public static String decodeAndExpand(String encoded) throws IOException { GZIPInputStream gzis = new GZIPInputStream( new Base64InputStream(new ByteArrayInputStream(encoded.getBytes(UTF_8)))); try {//from ww w. ja v a2 s .c o m return IOUtils.toString(gzis, UTF_8); } finally { gzis.close(); } }