List of usage examples for java.util.zip GZIPInputStream GZIPInputStream
public GZIPInputStream(InputStream in) throws IOException
From source file:com.oprisnik.semdroid.utils.FileUtils.java
public static Object loadObjectFromZipStream(InputStream input) throws ClassNotFoundException, IOException { return loadObjectFromStream(new GZIPInputStream(input)); }
From source file:com.microsoft.applicationinsights.core.volume.FakeTransmissionOutput.java
@Override public boolean send(Transmission transmission) { ByteArrayOutputStream out = null; try {// www. j a v a2s .co m out = new ByteArrayOutputStream(); IOUtils.copy(new GZIPInputStream(new ByteArrayInputStream(transmission.getContent())), out); String[] strings = new String(out.toByteArray()).split(System.getProperty("line.separator")); testResultsVerifier.notifyEventsArrival(strings.length); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; }
From source file:com.epam.wilma.gepard.testclient.compression.gzip.GzipCompressor.java
/** * De-Compress the input stream from GZIP. * * @param inputStream is the input//ww w. ja v a 2s.c o m * @return with de-compressed format * @throws IOException if problem occurs during the de-compression */ public ByteArrayInputStream decompress(final InputStream inputStream) throws IOException { OutputStream writer = new ByteArrayOutputStream(); GZIPInputStream gzipStream = new GZIPInputStream(inputStream); IOUtils.copy(gzipStream, writer); return new ByteArrayInputStream(((ByteArrayOutputStream) writer).toByteArray()); }
From source file:de.langmi.spring.batch.examples.readers.file.gzip.GZipBufferedReaderFactory.java
/** * Creates Bufferedreader for gzip Resource, handles normal resources * too.//w w w .ja v a2 s . c om * * @param resource * @param encoding * @return * @throws UnsupportedEncodingException * @throws IOException */ @Override public BufferedReader create(Resource resource, String encoding) throws UnsupportedEncodingException, IOException { for (String suffix : gzipSuffixes) { // test for filename and description, description is used when // handling itemStreamResources if (resource.getFilename().endsWith(suffix) || resource.getDescription().endsWith(suffix)) { return new BufferedReader( new InputStreamReader(new GZIPInputStream(resource.getInputStream()), encoding)); } } return new BufferedReader(new InputStreamReader(resource.getInputStream(), encoding)); }
From source file:com.thoughtworks.go.websocket.MessageEncoding.java
public static Message decodeMessage(InputStream input) { try {/*from www . j ava 2s . c om*/ try (GZIPInputStream zipStream = new GZIPInputStream(input)) { String jsonStr = new String(IOUtils.toByteArray(zipStream), StandardCharsets.UTF_8); return gson.fromJson(jsonStr, Message.class); } } catch (IOException e) { throw bomb(e); } }
From source file:com.netflix.dyno.connectionpool.impl.utils.ZipUtils.java
/** * Decompresses the given byte array//from ww w . jav a 2 s .c o m * * @param compressed byte array input * @return decompressed data in string format * @throws IOException */ public static String decompressStringNonBase64(byte[] compressed) throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(compressed); InputStream gis = new GZIPInputStream(is); return new String(IOUtils.toByteArray(gis), StandardCharsets.UTF_8); }
From source file:klapersuite.prismanalysis.linux.PrismRunner.java
public boolean extractTar() throws IOException { logger.info("Extract prism archive: " + prismArchive); InputStream gzStream = prismArchive.openStream(); TarInputStream tarStream = new TarInputStream(new GZIPInputStream(gzStream)); TarEntry tarEntry;/* w ww . j a va 2 s .c om*/ while ((tarEntry = tarStream.getNextEntry()) != null) { File destPath = new File(prismDestinationDir, tarEntry.getName()); if (tarEntry.isDirectory()) { destPath.mkdir(); continue; } FileOutputStream fout = new FileOutputStream(destPath); tarStream.copyEntryContents(fout); fout.close(); if (tarEntry.getName().endsWith("install.sh")) destPath.setExecutable(true); } tarStream.close(); gzStream.close(); return true; }
From source file:co.freeside.betamax.message.AbstractMessage.java
/** * A default implementation that decodes the byte stream from `getBodyAsBinary`. Implementations can override this * if they have a simpler way of doing it. *//*from w w w.j a va2s . c o m*/ public Reader getBodyAsText() throws IOException { InputStream stream; String encoding = getEncoding(); if ("gzip".equals(encoding)) { stream = new GZIPInputStream(getBodyAsBinary()); } else if ("deflate".equals(encoding)) { stream = new InflaterInputStream(getBodyAsBinary()); } else { stream = getBodyAsBinary(); } return new InputStreamReader(stream, getCharset()); }
From source file:de.qaware.chronix.converter.common.Compression.java
/** * Decompresses the given byte[]/*from w w w . j a va 2s . c o m*/ * * @param compressed - the compressed bytes * @return an input stream on the decompressed bytes */ public static InputStream decompressToStream(byte[] compressed) { if (compressed == null) { LOGGER.debug("Compressed bytes[] are null. Returning null."); return null; } try { return new GZIPInputStream(new ByteArrayInputStream(compressed)); } catch (IOException e) { LOGGER.error("Exception occurred while decompressing gzip stream. Returning null.", e); } return null; }
From source file:com.unilever.audit.services2.VisitSync.java
@POST @Produces("application/json") @Consumes("text/plain") public String postJson(byte[] jsonObj) throws IOException { JSONObject result = new JSONObject(); JSONArray failedIds = new JSONArray(); boolean status = true; byte[] buffer; try {// ww w . java 2s. co m ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(jsonObj)); IOUtils.copy(in, out); buffer = out.toByteArray(); System.out.println("======================siiiize" + buffer.length); JSONObject obj = new JSONObject(new String(buffer)); JSONArray visitsArr = obj.getJSONArray("visits"); for (int i = 0; i < visitsArr.length(); i++) { try { utx.begin(); } catch (javax.transaction.NotSupportedException ex) { ex.printStackTrace(); } catch (SystemException ex) { ex.printStackTrace(); } JSONObject visitObj = (JSONObject) visitsArr.get(i); Visit v = new Visit(); v.setId(visitObj.getString("id")); Customers c = em.getReference(Customers.class, new BigDecimal(visitObj.getInt("customerid"))); v.setCustomerid(c); Merchandisers m = em.getReference(Merchandisers.class, new BigDecimal(visitObj.getInt("merchid"))); v.setMerchandiserid(m); try { Date date = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy") .parse(visitObj.getString("finishdate")); v.setVisitdate(date); } catch (java.text.ParseException ex) { ex.printStackTrace(); } v.setSubmitteddate(new Date()); try { em.persist(v); System.out.println("Timeeeeeeeeeeeeee ============= " + (v.getSubmitteddate().getTime() - v.getVisitdate().getTime())); utx.commit(); } catch (Exception ex) { status = false; failedIds.put(v.getId()); } } result.put("status", status); result.put("failedIds", failedIds); } catch (JSONException ex) { ex.printStackTrace(); } return result.toString(); }