List of usage examples for java.util.zip GZIPInputStream GZIPInputStream
public GZIPInputStream(InputStream in) throws IOException
From source file:com.epam.wilma.test.server.compress.gzip.GzipDecompressor.java
/** * Decompresses an input stream from gzip. * @param body the inputstream that is decompressed. * @return the decompressed {@link ByteArrayOutputStream} *///ww w. jav a 2 s .co m public ByteArrayOutputStream decompress(final InputStream body) { ByteArrayOutputStream writer = new ByteArrayOutputStream(); try { GZIPInputStream gzipStream = new GZIPInputStream(body); IOUtils.copy(gzipStream, writer); } catch (IOException e) { logger.error("Error when decompress inputStream, exception message:" + e.getMessage()); } return writer; }
From source file:com.github.sdbg.debug.core.util.JsonTests.java
public void xxx_test_parse100() throws IOException, JSONException { InputStream in = JsonTests.class.getResourceAsStream("test1.json.gz"); GZIPInputStream gzipIn = new GZIPInputStream(in); String string = Streams.loadAndClose(new InputStreamReader(gzipIn, "UTF-8")); long start = System.nanoTime(); int iterations = 100; for (int i = 0; i < iterations; i++) { @SuppressWarnings("unused") JSONObject obj = new JSONObject(string); }/*from w w w . j a va 2s.c o m*/ long elapsed = System.nanoTime() - start; double mb = (string.length() * iterations) / (1024.0 * 1024.0); double sec = elapsed / (1000 * 1000 * 1000.0); System.out.println(String.format("%.2f MB/sec", (mb / sec))); }
From source file:edu.cornell.med.icb.goby.algorithmic.data.WeightsInfo.java
/** * Load weights info from disk./*from w w w.j av a2 s .c o m*/ * * @param filename The name of the file to load * @return The populated WeightsInfo object read from the file * @throws IOException If the file cannot be read * @throws ClassNotFoundException if the file contains a class that cannot be found. */ public static WeightsInfo load(final String filename) throws IOException, ClassNotFoundException { GZIPInputStream inputStream = null; try { inputStream = new GZIPInputStream(new FileInputStream(filename)); return (WeightsInfo) BinIO.loadObject(inputStream); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:com.socioffice.grabmenu.model.JSONRequest.java
public static JSONObject SendHttpPost(String URL, JSONObject jsonObjSend) { try {//from w w w . ja v a 2 s . c om DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpPostRequest = new HttpPost(URL); StringEntity se; se = new StringEntity(jsonObjSend.toString()); // Set HTTP parameters httpPostRequest.setEntity(se); httpPostRequest.setHeader("Accept", "application/json"); httpPostRequest.setHeader("Content-type", "application/json"); // only set this parameter if you would like to use gzip compression httpPostRequest.setHeader("Accept-Encoding", "gzip"); long t = System.currentTimeMillis(); HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest); Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis() - t) + "ms]"); // Get hold of the response entity (-> the data): HttpEntity entity = response.getEntity(); if (entity != null) { // Read the content stream InputStream instream = entity.getContent(); Header contentEncoding = response.getFirstHeader("Content-Encoding"); if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) { instream = new GZIPInputStream(instream); } // convert content stream to a String String resultString = convertStreamToString(instream); instream.close(); resultString = resultString.substring(1, resultString.length() - 1); // remove wrapping "[" and // "]" // Transform the String into a JSONObject JSONObject jsonObjRecv = new JSONObject(resultString); // Raw DEBUG output of our received JSON object: Log.i(TAG, "<jsonobject>\n" + jsonObjRecv.toString() + "\n</jsonobject>"); return jsonObjRecv; } } catch (Exception e) { // More about HTTP exception handling in another tutorial. // For now we just print the stack trace. e.printStackTrace(); } return null; }
From source file:ca.dal.cs.csci4126.quizboard.library.HttpClient.java
public static JSONObject SendHttpPost(String URL, JSONObject jsonObjSend) { try {/* ww w .j av a 2 s . c o m*/ DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpPostRequest = new HttpPost(URL); StringEntity se; se = new StringEntity(jsonObjSend.toString()); // Set HTTP parameters httpPostRequest.setEntity(se); httpPostRequest.setHeader("Accept", "application/json"); httpPostRequest.setHeader("Content-type", "application/json"); httpPostRequest.setHeader("Accept-Encoding", "gzip"); // only set this parameter if you would like to use gzip compression long t = System.currentTimeMillis(); HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest); Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis() - t) + "ms]"); // Get hold of the response entity (-> the data): HttpEntity entity = response.getEntity(); if (entity != null) { // Read the content stream InputStream instream = entity.getContent(); Header contentEncoding = response.getFirstHeader("Content-Encoding"); if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) { instream = new GZIPInputStream(instream); } // convert content stream to a String String resultString = convertStreamToString(instream); instream.close(); resultString = resultString.substring(1, resultString.length() - 1); // remove wrapping "[" and "]" // Transform the String into a JSONObject JSONObject jsonObjRecv = new JSONObject(resultString); // Raw DEBUG output of our received JSON object: Log.i(TAG, "<JSONObject>\n" + jsonObjRecv.toString() + "\n</JSONObject>"); return jsonObjRecv; } } catch (Exception e) { // More about HTTP exception handling in another tutorial. // For now we just print the stack trace. e.printStackTrace(); } return null; }
From source file:com.example.montxu.magik_repair.HttpClient.java
public static JSONObject SendHttpPost(String URL, JSONObject jsonObjSend) { try {// w ww .ja va 2s . co m DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpPostRequest = new HttpPost(URL); StringEntity se; se = new StringEntity(jsonObjSend.toString()); // Set HTTP parameters httpPostRequest.setEntity(se); httpPostRequest.setHeader("Accept", "application/json"); httpPostRequest.setHeader("Content-type", "application/json"); httpPostRequest.setHeader("Accept-Encoding", "gzip"); // only set this parameter if you would like to use gzip compression long t = System.currentTimeMillis(); HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest); Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis() - t) + "ms]"); // Get hold of the response entity (-> the data): HttpEntity entity = response.getEntity(); if (entity != null) { // Read the content stream InputStream instream = entity.getContent(); Header contentEncoding = response.getFirstHeader("Content-Encoding"); if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) { instream = new GZIPInputStream(instream); } // convert content stream to a String String resultString = convertStreamToString(instream); instream.close(); //resultString = resultString.substring(1,resultString.length()-1); // remove wrapping "[" and "]" // Transform the String into a JSONObject JSONObject jsonObjRecv = new JSONObject(resultString); // Raw DEBUG output of our received JSON object: Log.i(TAG, "<JSONObject>\n" + jsonObjRecv.toString() + "\n</JSONObject>"); return jsonObjRecv; } } catch (Exception e) { // More about HTTP exception handling in another tutorial. // For now we just print the stack trace. e.printStackTrace(); } return null; }
From source file:drawnzer.anurag.tarHelper.TarManager.java
public TarManager(File file, String pathToShow) throws IOException { // TODO Auto-generated constructor stub if (file.getName().endsWith(".tar.gz")) tar = new TarArchiveInputStream( new GZIPInputStream(new BufferedInputStream(new FileInputStream(file)))); else if (file.getName().endsWith(".tar.bz2") || file.getName().endsWith(".TAR.BZ2")) tar = new TarArchiveInputStream( new BZip2CompressorInputStream(new BufferedInputStream(new FileInputStream(file)))); else//from w w w . j av a2 s. c o m tar = new TarArchiveInputStream(new BufferedInputStream(new FileInputStream(file))); path = pathToShow; }
From source file:edu.scripps.fl.pubchem.app.cids.WriteSDFStage.java
@Override public void process(Object obj) throws StageException { URL url = (URL) obj;//from w ww . ja v a2s .c o m try { File outputFile = newOutputFile(counter.incrementAndGet()); logger.info("Writing SDF file: " + outputFile); IOUtils.copy(new GZIPInputStream(url.openStream()), FileUtils.openOutputStream(outputFile)); emit(outputFile); } catch (Exception ex) { throw new StageException(this, ex); } }
From source file:com.google.android.feeds.ContentHandlerUtils.java
/** * Returns the uncompressed {@link InputStream} for the given * {@link URLConnection}.// w w w . j a v a 2 s. c o m */ public static InputStream getUncompressedInputStream(URLConnection connection) throws IOException { InputStream source = connection.getInputStream(); String encoding = connection.getContentEncoding(); if ("gzip".equalsIgnoreCase(encoding)) { return new GZIPInputStream(source); } else if ("deflate".equalsIgnoreCase(encoding)) { boolean noHeader = true; Inflater inflater = new Inflater(noHeader); return new InflaterInputStream(source, inflater); } else { return source; } }
From source file:edu.cornell.med.icb.goby.alignments.UpgradeTo1_9_6.java
public void upgrade(String basename, AlignmentReaderImpl reader) throws IOException { if (!"1.9.5-".equals(reader.getGobyVersion())) return;/* w ww . jav a 2s . com*/ final GZIPInputStream indexStream = new GZIPInputStream(new RepositionableInputStream(basename + ".index")); final CodedInputStream codedInput = CodedInputStream.newInstance(indexStream); codedInput.setSizeLimit(Integer.MAX_VALUE); final Alignments.AlignmentIndex index = Alignments.AlignmentIndex.parseFrom(codedInput); LongArrayList indexOffsets = new LongArrayList(); LongArrayList upgradedOffsets = new LongArrayList(); LongArrayList indexAbsolutePositions = new LongArrayList(); LongArrayList upgradedIndexAbsolutePositions = new LongArrayList(); for (final long offset : index.getOffsetsList()) { indexOffsets.add(offset); } for (final long absolutePosition : index.getAbsolutePositionsList()) { indexAbsolutePositions.add(absolutePosition); } // trimming is essential for the binary search to work reliably with the result of elements(): indexAbsolutePositions.trim(); indexOffsets.trim(); long[] targetPositionOffsets; int[] targetLengths = reader.getTargetLength(); //prepare according to new indexing scheme: targetPositionOffsets = new long[targetLengths.length]; targetPositionOffsets[0] = 0; for (int targetIndex = 1; targetIndex < targetLengths.length; targetIndex++) { targetPositionOffsets[targetIndex] = targetLengths[targetIndex - 1] + targetPositionOffsets[targetIndex - 1]; } long previousAbsolutePosition = -1; ProgressLogger progress = new ProgressLogger(LOG); progress.expectedUpdates = indexOffsets.size(); progress.priority = Level.INFO; progress.start(); // push the very first entry to the index at offset zero. This is necessary because 1.9.5 did not include // offset information and absolute position for the very first entry of the alignment. Alignments.AlignmentEntry entry = reader.next(); previousAbsolutePosition = pushEntryToIndex(upgradedOffsets, upgradedIndexAbsolutePositions, targetPositionOffsets, previousAbsolutePosition, 0, entry); for (long indexOffset : indexOffsets) { // for each offset in the entries file, obtain the first entry then recode absolute position: entry = fetchFirstEntry(reader, indexOffset); previousAbsolutePosition = pushEntryToIndex(upgradedOffsets, upgradedIndexAbsolutePositions, targetPositionOffsets, previousAbsolutePosition, indexOffset, entry); progress.lightUpdate(); } progress.stop(); writeIndex(basename, upgradedOffsets, upgradedIndexAbsolutePositions); upgradeHeaderVersion(basename); if (verbose) { System.out.printf("alignment %s upgraded successfully.%n", basename); } }