List of usage examples for java.util.zip GZIPInputStream read
public int read() throws IOException
From source file:lapin.load.Loader.java
static private byte[] decompress(byte[] bytes) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(bytes); GZIPInputStream gin = new GZIPInputStream(bin); ByteArrayOutputStream bout = new ByteArrayOutputStream(); int b;/* w w w .java 2 s . co m*/ while ((b = gin.read()) != -1) bout.write(b); bout.flush(); IO.close(gin); IO.close(bin); IO.close(bout); return bout.toByteArray(); }
From source file:org.opendatakit.common.utils.WebUtils.java
/** * Decode a safeEncode() string./*from ww w .j a va 2 s. co m*/ * * @param encodedWebsafeString * @return rawString */ public static String safeDecode(String encodedWebsafeString) { if (encodedWebsafeString == null || encodedWebsafeString.length() == 0) { return encodedWebsafeString; } try { ByteArrayInputStream in = new ByteArrayInputStream( Base64.decodeBase64(encodedWebsafeString.getBytes(CharEncoding.UTF_8))); GZIPInputStream gzip = new GZIPInputStream(in); ByteArrayOutputStream out = new ByteArrayOutputStream(); int ch = gzip.read(); while (ch >= 0) { out.write(ch); ch = gzip.read(); } gzip.close(); out.flush(); out.close(); return new String(out.toByteArray(), CharEncoding.UTF_8); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new IllegalArgumentException("Unexpected failure: " + e.toString()); } catch (IOException e) { e.printStackTrace(); throw new IllegalArgumentException("Unexpected failure: " + e.toString()); } }
From source file:com.ning.billing.beatrix.osgi.SetupBundleWithAssertion.java
private static File unGzip(final File inputFile, final File outputDir) throws IOException { GZIPInputStream in = null; FileOutputStream out = null;/*from w ww. j av a2 s . c om*/ try { final File outputFile = new File(outputDir, inputFile.getName().substring(0, inputFile.getName().length() - 3)); in = new GZIPInputStream(new FileInputStream(inputFile)); out = new FileOutputStream(outputFile); for (int c = in.read(); c != -1; c = in.read()) { out.write(c); } return outputFile; } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } }
From source file:org.killbill.billing.beatrix.integration.osgi.util.SetupBundleWithAssertion.java
private static File unGzip(final File inputFile, final File outputDir) throws IOException { GZIPInputStream in = null; FileOutputStream out = null;/*from w w w . j a v a 2 s . c om*/ try { final File outputFile = new File(outputDir, inputFile.getName().substring(0, inputFile.getName().length() - 3)); in = new GZIPInputStream(new FileInputStream(inputFile)); out = new FileOutputStream(outputFile); for (int c = in.read(); c != -1; c = in.read()) { out.write(c); } return outputFile; } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } }
From source file:com.softinstigate.restheart.integrationtest.ContentEncodingIT.java
@Test public void testGzipAcceptEncoding() throws Exception { Response resp = notDecompressingExecutor .execute(Request.Get(rootUri).addHeader(Headers.ACCEPT_ENCODING_STRING, Headers.GZIP.toString())); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp);/* w w w . j a va 2 s . co m*/ HttpEntity entity = httpResp.getEntity(); assertNotNull(entity); StatusLine statusLine = httpResp.getStatusLine(); assertNotNull(statusLine); String content = EntityUtils.toString(entity); Header h = httpResp.getFirstHeader("Content-Encoding"); assertNotNull("check accept encoding header not null", h); assertEquals("check accept encoding header value", Headers.GZIP.toString(), h.getValue()); assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode()); try { GZIPInputStream gzipis = new GZIPInputStream( new ByteArrayInputStream(content.getBytes(StandardCharsets.ISO_8859_1))); while (gzipis.read() > 0) { } } catch (Exception ex) { fail("check decompressing content"); } }
From source file:com.panet.imeta.www.SlaveServerJobStatus.java
public SlaveServerJobStatus(Node jobStatusNode) { this();/* w w w. ja va2s.com*/ jobName = XMLHandler.getTagValue(jobStatusNode, "jobname"); statusDescription = XMLHandler.getTagValue(jobStatusNode, "status_desc"); errorDescription = XMLHandler.getTagValue(jobStatusNode, "error_desc"); String loggingString64 = XMLHandler.getTagValue(jobStatusNode, "logging_string"); // This is a Base64 encoded GZIP compressed stream of data. // try { byte[] bytes = new byte[] {}; if (loggingString64 != null) bytes = Base64.decodeBase64(loggingString64.getBytes()); if (bytes.length > 0) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); GZIPInputStream gzip = new GZIPInputStream(bais); int c; StringBuffer buffer = new StringBuffer(); while ((c = gzip.read()) != -1) buffer.append((char) c); gzip.close(); loggingString = buffer.toString(); } else { loggingString = ""; } } catch (IOException e) { loggingString = "Unable to decode logging from remote server : " + e.toString() + Const.CR + Const.getStackTracker(e) + Const.CR; } // get the result object, if there is any... // Node resultNode = XMLHandler.getSubNode(jobStatusNode, Result.XML_TAG); if (resultNode != null) { try { result = new Result(resultNode); } catch (IOException e) { loggingString += "Unable to serialize result object as XML" + Const.CR + Const.getStackTracker(e) + Const.CR; } } }
From source file:org.pentaho.di.www.SlaveServerJobStatus.java
public SlaveServerJobStatus(Node jobStatusNode) throws KettleException { this();/*from ww w. ja va 2 s .c om*/ jobName = XMLHandler.getTagValue(jobStatusNode, "jobname"); id = XMLHandler.getTagValue(jobStatusNode, "id"); statusDescription = XMLHandler.getTagValue(jobStatusNode, "status_desc"); errorDescription = XMLHandler.getTagValue(jobStatusNode, "error_desc"); firstLoggingLineNr = Const.toInt(XMLHandler.getTagValue(jobStatusNode, "first_log_line_nr"), 0); lastLoggingLineNr = Const.toInt(XMLHandler.getTagValue(jobStatusNode, "last_log_line_nr"), 0); String loggingString64 = XMLHandler.getTagValue(jobStatusNode, "logging_string"); // This is a Base64 encoded GZIP compressed stream of data. // try { byte[] bytes = new byte[] {}; if (loggingString64 != null) bytes = Base64.decodeBase64(loggingString64.getBytes()); if (bytes.length > 0) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); GZIPInputStream gzip = new GZIPInputStream(bais); int c; StringBuffer buffer = new StringBuffer(); while ((c = gzip.read()) != -1) buffer.append((char) c); gzip.close(); loggingString = buffer.toString(); } else { loggingString = ""; } } catch (IOException e) { loggingString = "Unable to decode logging from remote server : " + e.toString() + Const.CR + Const.getStackTracker(e) + Const.CR; } // get the result object, if there is any... // Node resultNode = XMLHandler.getSubNode(jobStatusNode, Result.XML_TAG); if (resultNode != null) { try { result = new Result(resultNode); } catch (KettleException e) { loggingString += "Unable to serialize result object as XML" + Const.CR + Const.getStackTracker(e) + Const.CR; } } }
From source file:com.panet.imeta.www.SlaveServerTransStatus.java
public SlaveServerTransStatus(Node transStatusNode) { this();/*from w w w.j a v a2s. c o m*/ transName = XMLHandler.getTagValue(transStatusNode, "transname"); statusDescription = XMLHandler.getTagValue(transStatusNode, "status_desc"); errorDescription = XMLHandler.getTagValue(transStatusNode, "error_desc"); paused = "Y".equalsIgnoreCase(XMLHandler.getTagValue(transStatusNode, "paused")); Node statusListNode = XMLHandler.getSubNode(transStatusNode, "stepstatuslist"); int nr = XMLHandler.countNodes(statusListNode, StepStatus.XML_TAG); for (int i = 0; i < nr; i++) { Node stepStatusNode = XMLHandler.getSubNodeByNr(statusListNode, StepStatus.XML_TAG, i); StepStatus stepStatus = new StepStatus(stepStatusNode); stepStatusList.add(stepStatus); } String loggingString64 = XMLHandler.getTagValue(transStatusNode, "logging_string"); // This is a Base64 encoded GZIP compressed stream of data. try { byte[] bytes = new byte[] {}; if (loggingString64 != null) bytes = Base64.decodeBase64(loggingString64.getBytes()); if (bytes.length > 0) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); GZIPInputStream gzip = new GZIPInputStream(bais); int c; StringBuffer buffer = new StringBuffer(); while ((c = gzip.read()) != -1) buffer.append((char) c); gzip.close(); loggingString = buffer.toString(); } else { loggingString = ""; } } catch (IOException e) { loggingString = "Unable to decode logging from remote server : " + e.toString() + Const.CR + Const.getStackTracker(e); } // get the result object, if there is any... // Node resultNode = XMLHandler.getSubNode(transStatusNode, Result.XML_TAG); if (resultNode != null) { try { result = new Result(resultNode); } catch (IOException e) { loggingString += "Unable to serialize result object as XML" + Const.CR + Const.getStackTracker(e) + Const.CR; } } }
From source file:org.pentaho.di.www.SlaveServerTransStatus.java
public SlaveServerTransStatus(Node transStatusNode) { this();/* ww w . j av a 2s . c o m*/ id = XMLHandler.getTagValue(transStatusNode, "id"); transName = XMLHandler.getTagValue(transStatusNode, "transname"); statusDescription = XMLHandler.getTagValue(transStatusNode, "status_desc"); errorDescription = XMLHandler.getTagValue(transStatusNode, "error_desc"); paused = "Y".equalsIgnoreCase(XMLHandler.getTagValue(transStatusNode, "paused")); Node statusListNode = XMLHandler.getSubNode(transStatusNode, "stepstatuslist"); int nr = XMLHandler.countNodes(statusListNode, StepStatus.XML_TAG); for (int i = 0; i < nr; i++) { Node stepStatusNode = XMLHandler.getSubNodeByNr(statusListNode, StepStatus.XML_TAG, i); StepStatus stepStatus = new StepStatus(stepStatusNode); stepStatusList.add(stepStatus); } firstLoggingLineNr = Const.toInt(XMLHandler.getTagValue(transStatusNode, "first_log_line_nr"), 0); lastLoggingLineNr = Const.toInt(XMLHandler.getTagValue(transStatusNode, "last_log_line_nr"), 0); String loggingString64 = XMLHandler.getTagValue(transStatusNode, "logging_string"); // This is a Base64 encoded GZIP compressed stream of data. try { byte[] bytes = new byte[] {}; if (loggingString64 != null) bytes = Base64.decodeBase64(loggingString64.getBytes()); if (bytes.length > 0) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); GZIPInputStream gzip = new GZIPInputStream(bais); int c; StringBuffer buffer = new StringBuffer(); while ((c = gzip.read()) != -1) buffer.append((char) c); gzip.close(); loggingString = buffer.toString(); } else { loggingString = ""; } } catch (IOException e) { loggingString = "Unable to decode logging from remote server : " + e.toString() + Const.CR + Const.getStackTracker(e); } // get the result object, if there is any... // Node resultNode = XMLHandler.getSubNode(transStatusNode, Result.XML_TAG); if (resultNode != null) { try { result = new Result(resultNode); } catch (KettleException e) { loggingString += "Unable to serialize result object as XML" + Const.CR + Const.getStackTracker(e) + Const.CR; } } }
From source file:net.sf.ehcache.constructs.web.PageInfoTest.java
private byte[] ungzip4(final byte[] gzip) throws IOException { byte[] buffer = new byte[500000]; int size = 0; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(gzip); GZIPInputStream gzipInputStream = new GZIPInputStream(byteArrayInputStream); int nextByte = 0; int counter = 0; while (nextByte != -1) { nextByte = gzipInputStream.read(); if (nextByte != -1) { buffer[counter] = (byte) nextByte; counter++;//from w ww. j a v a 2 s . co m size = counter; } } gzipInputStream.close(); byte[] unzipped = new byte[counter]; System.arraycopy(buffer, 0, unzipped, 0, counter); return unzipped; }