List of usage examples for java.util.zip GZIPInputStream GZIPInputStream
public GZIPInputStream(InputStream in) throws IOException
From source file:Main.java
public static Object readGZipCompressedObject(InputStream in) throws IOException, ClassNotFoundException { GZIPInputStream gis = new GZIPInputStream(in); ObjectInputStream ois = new ObjectInputStream(gis); return ois.readObject(); }
From source file:Main.java
static byte[] decompress(byte[] compressed) throws IOException { int nRead;/*from www .j a v a2s .co m*/ byte[] data = new byte[2048]; ByteArrayInputStream bis = new ByteArrayInputStream(compressed); GZIPInputStream gzip = new GZIPInputStream(bis); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); while ((nRead = gzip.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } bis.close(); gzip.close(); return buffer.toByteArray(); }
From source file:net.es.nsi.common.util.ContentType.java
public static byte[] decode2ByteArray(String contentType, InputStream is) throws IOException { if (XGZIP.equalsIgnoreCase(contentType)) { return IOUtils.toByteArray(new GZIPInputStream(is)); } else {/*from w w w . j av a 2 s.co m*/ return IOUtils.toByteArray(is); } }
From source file:Main.java
static byte[] decompress(byte[] compressed) throws IOException { int nRead;//from w ww . ja v a 2s .co m byte[] data = new byte[2048]; ByteArrayInputStream bis = new ByteArrayInputStream(compressed); GZIPInputStream gzip = new GZIPInputStream(bis); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); while ((nRead = gzip.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } gzip.close(); bis.close(); return buffer.toByteArray(); }
From source file:ca.uhn.fhir.jpa.dao.GZipUtil.java
public static String decompress(byte[] theResource) { GZIPInputStream is;/*from w ww .j a v a 2 s .com*/ try { is = new GZIPInputStream(new ByteArrayInputStream(theResource)); return IOUtils.toString(is, "UTF-8"); } catch (IOException e) { throw new DataFormatException("Failed to decompress contents", e); } }
From source file:Main.java
/** * @param xmlFile is the file to read//from w ww . j av a 2 s . co m * @param compress if true, the file is assumed to be compressed with GZIP * @return the Document contained in that file */ public static Document readFile(File xmlFile, boolean compress) { ensureFactory(); try { DocumentBuilder builder = mFactory.newDocumentBuilder(); //builder.setEntityResolver(new EntityUtils()); InputStream is = new FileInputStream(xmlFile); if (compress) is = new GZIPInputStream(is); Document ret = builder.parse(is); is.close(); return ret; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
private static InputStream toInputStream(File file) throws IOException { InputStream in = new FileInputStream(file); if (file.getName().endsWith(".gz")) { in = new GZIPInputStream(in); }// w w w . j a va2s. co m return in; }
From source file:Main.java
/** * unzip some gzip compressed data/*from w w w . ja v a 2 s . c o m*/ * @param bytes the data to uncompress * @return the uncompressed data */ public static String gzipDecompress(byte[] bytes) { ByteArrayInputStream stream = new ByteArrayInputStream(bytes); try { GZIPInputStream gs = new GZIPInputStream(stream); BufferedInputStream bufis = new BufferedInputStream(gs); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int len; while ((len = bufis.read(buf)) > 0) { bos.write(buf, 0, len); } return bos.toString(); } catch (IOException e) { return null; } }
From source file:de.ocarthon.core.utility.GzipCompression.java
public static String decompress(InputStream inputStream) throws IOException { GZIPInputStream gis = null;//from ww w . j a va 2s . co m String json; try { gis = new GZIPInputStream(inputStream); json = IOUtils.toString(gis, "UTF-8"); } finally { IOUtils.closeQuietly(gis); } return json; }
From source file:com.mirth.connect.connectors.http.HttpUtil.java
public static String uncompressGzip(byte[] content, String charset) throws IOException { GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(content)); StringWriter writer = new StringWriter(); IOUtils.copy(gzis, writer, charset); return writer.toString(); }