List of usage examples for java.util.zip GZIPInputStream close
public void close() throws IOException
From source file:backtype.storm.utils.Utils.java
public static byte[] gunzip(byte[] data) { try {//ww w .ja v a 2 s .com ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(data); GZIPInputStream in = new GZIPInputStream(bis); byte[] buffer = new byte[1024]; int len = 0; while ((len = in.read(buffer)) >= 0) { bos.write(buffer, 0, len); } in.close(); bos.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.apache.myfaces.shared_ext202patch.util.StateUtils.java
public static final byte[] decompress(byte[] bytes) { if (bytes == null) throw new NullPointerException("byte[] bytes"); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[bytes.length]; int length;/* w w w . j a va2s . c om*/ try { GZIPInputStream gis = new GZIPInputStream(bais); while ((length = gis.read(buffer)) != -1) { baos.write(buffer, 0, length); } byte[] moreBytes = baos.toByteArray(); baos.close(); bais.close(); gis.close(); baos = null; bais = null; gis = null; return moreBytes; } catch (IOException e) { throw new FacesException(e); } }
From source file:org.apache.myfaces.shared.util.StateUtils.java
public static final byte[] decompress(byte[] bytes) { if (bytes == null) { throw new NullPointerException("byte[] bytes"); }//from w w w . j av a 2 s . c om ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[bytes.length]; int length; try { GZIPInputStream gis = new GZIPInputStream(bais); while ((length = gis.read(buffer)) != -1) { baos.write(buffer, 0, length); } byte[] moreBytes = baos.toByteArray(); baos.close(); bais.close(); gis.close(); baos = null; bais = null; gis = null; return moreBytes; } catch (IOException e) { throw new FacesException(e); } }
From source file:org.apache.oozie.compression.GzipCompressionCodec.java
public byte[] decompressToBytes(DataInputStream dais) throws IOException { GZIPInputStream gzipIn = new GZIPInputStream(dais); byte[] decompress = IOUtils.toByteArray(gzipIn); gzipIn.close(); return decompress; }
From source file:org.apache.oozie.compression.GzipCompressionCodec.java
public String decompressToString(DataInputStream dais) throws IOException { GZIPInputStream gzipIn = new GZIPInputStream(dais); String decompress = IOUtils.toString(gzipIn, CodecFactory.UTF_8_ENCODING); gzipIn.close(); return decompress; }
From source file:weka.clusterers.InstanceWithCanopyAssignments.java
public static long[] decodeCanopiesFromBase64(String base64) throws Exception { byte[] bytes; long[] canopies = null; if (base64 == null) { bytes = new byte[] {}; } else {//from ww w .j av a 2 s . c o m bytes = Base64.decodeBase64(base64.getBytes()); } if (bytes.length > 0) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); GZIPInputStream gzip = new GZIPInputStream(bais); BufferedInputStream bi = new BufferedInputStream(gzip); try { byte[] result = new byte[] {}; byte[] extra = new byte[1000000]; int nrExtra = bi.read(extra); while (nrExtra >= 0) { // add it to bytes... // int newSize = result.length + nrExtra; byte[] tmp = new byte[newSize]; for (int i = 0; i < result.length; i++) { tmp[i] = result[i]; } for (int i = 0; i < nrExtra; i++) { tmp[result.length + i] = extra[i]; } // change the result result = tmp; nrExtra = bi.read(extra); } bytes = result; } finally { gzip.close(); } bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); try { canopies = (long[]) ois.readObject(); } finally { ois.close(); } } if (canopies == null || canopies.length == 0) { throw new Exception("No canopy assignments decoded!"); } return canopies; }
From source file:org.forgerock.openam.cts.utils.blob.strategies.CompressionStrategy.java
/** * Decompress the Tokens binary object.//from ww w .j ava2s . co m * * @param token Non null Token to modify. * * @throws TokenStrategyFailedException {@inheritDoc} */ @Override public void reverse(Token token) throws TokenStrategyFailedException { bout.reset(); try { GZIPInputStream inputStream = new GZIPInputStream(new ByteArrayInputStream(token.getBlob())); IOUtils.copy(inputStream, bout); inputStream.close(); } catch (IOException e) { throw new TokenStrategyFailedException(e); } token.setBlob(bout.toByteArray()); }
From source file:com.orange.clara.cloud.servicedbdumper.filer.compression.GzipCompressing.java
@Async public Future<Boolean> gunziptIt(OutputStream outputStream, InputStream inputStream) throws IOException { logger.debug("Start uncompressing..."); GZIPInputStream gzis = new GZIPInputStream(inputStream); ByteStreams.copy(gzis, outputStream); outputStream.flush();/*w ww .java 2 s . c om*/ outputStream.close(); gzis.close(); inputStream.close(); logger.debug("Finish uncompressing"); return new AsyncResult<Boolean>(true); }
From source file:org.unitime.commons.hibernate.blob.XmlBlobType.java
public Object assemble(Serializable cached, Object owner) throws HibernateException { try {/* w w w . ja v a 2s . co m*/ if (cached == null) return null; ByteArrayInputStream in = new ByteArrayInputStream((byte[]) cached); SAXReader reader = new SAXReader(); GZIPInputStream gzipInput = new GZIPInputStream(in); Document document = reader.read(gzipInput); gzipInput.close(); return document; } catch (DocumentException e) { throw new HibernateException(e.getMessage(), e); } catch (IOException e) { throw new HibernateException(e.getMessage(), e); } }
From source file:at.tlphotography.jAbuseReport.Reporter.java
/** * Read gz file.//from www . j ava2 s .c o m * * @param file * the file * @return the content hash map */ private static HashMap<String, String> readGZFile(File file) { GZIPInputStream gzip = null; BufferedReader br = null; HashMap<String, String> content = new HashMap<String, String>(); try { // open compressed file gzip = new GZIPInputStream(new FileInputStream(file)); br = new BufferedReader(new InputStreamReader(gzip)); // read it String line; while ((line = br.readLine()) != null) { if (checkLine(line)) { String addr = extractIp(line); content.put(addr, line); } } } catch (FileNotFoundException e) { System.err.println("Could not find '" + file.getAbsolutePath() + "'"); } catch (IOException e) { System.err.println("Could not read '" + file.getAbsolutePath() + "'"); } finally { // close all try { if (br != null) br.close(); if (gzip != null) gzip.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return content; }