List of usage examples for java.util.zip GZIPInputStream GZIPInputStream
public GZIPInputStream(InputStream in) throws IOException
From source file:edu.scripps.fl.pubchem.PubChemFactory.java
public InputStream getPubChemCsv(long aid) throws IOException { String archive = getAIDArchive(aid); String sUrl = String.format(pubchemBioAssayUrlFormat, ftpUser, ftpPass, "Data", archive); String szip = String.format("zip:%s!/%s/%s.csv.gz", sUrl, archive, aid); log.debug(sUrl);/*from w w w .java 2s.c o m*/ FileObject fo = VFS.getManager().resolveFile(szip); log.debug("Resolved file: " + szip); InputStream is = fo.getContent().getInputStream(); return new GZIPInputStream(is); }
From source file:jetbrains.exodus.util.CompressBackupUtilTest.java
@Test public void testFolderArchived() throws Exception { File src = new File(randName); src.mkdir();/*from w w w .j a v a2 s . c om*/ FileWriter fw = new FileWriter(new File(src, "1.txt")); fw.write("12345"); fw.close(); fw = new FileWriter(new File(src, "2.txt")); fw.write("12"); fw.close(); CompressBackupUtil.tar(src, dest); Assert.assertTrue("No destination archive created", dest.exists()); TarArchiveInputStream tai = new TarArchiveInputStream( new GZIPInputStream(new BufferedInputStream(new FileInputStream(dest)))); ArchiveEntry entry1 = tai.getNextEntry(); ArchiveEntry entry2 = tai.getNextEntry(); if (entry1.getName().compareTo(entry2.getName()) > 0) { // kinda sort them lol ArchiveEntry tmp = entry1; entry1 = entry2; entry2 = tmp; } Assert.assertNotNull("No entry found in destination archive", entry1); Assert.assertEquals("Entry has wrong size", 5, entry1.getSize()); System.out.println(entry1.getName()); Assert.assertEquals("Entry has wrong relative path", src.getName() + "/1.txt", entry1.getName()); System.out.println(entry2.getName()); Assert.assertEquals("Entry has wrong size", 2, entry2.getSize()); Assert.assertEquals("Entry has wrong relative path", src.getName() + "/2.txt", entry2.getName()); }
From source file:edu.stanford.muse.index.NER.java
public static void readLocationsWG() { InputStream is = null;//www . java 2 s . c o m try { is = new GZIPInputStream(NER.class.getClassLoader().getResourceAsStream("WG.locations.txt.gz")); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is, "UTF-8")); while (true) { String line = lnr.readLine(); if (line == null) break; StringTokenizer st = new StringTokenizer(line, "\t"); if (st.countTokens() == 4) { String locationName = st.nextToken(); String canonicalName = locationName.toLowerCase(); if (locationsToSuppress.contains(canonicalName)) continue; String lat = st.nextToken(); String longi = st.nextToken(); String pop = st.nextToken(); long popl = Long.parseLong(pop); float latf = ((float) Integer.parseInt(lat)) / 100.0f; float longif = ((float) Integer.parseInt(longi)) / 100.0f; Long existingPop = populations.get(canonicalName); if (existingPop == null || popl > existingPop) { populations.put(canonicalName, popl); locations.put(canonicalName, new LocationInfo(locationName, Float.toString(latf), Float.toString(longif))); } } } if (is != null) is.close(); } catch (Exception e) { log.warn("Unable to read World Gazetteer file, places info may be inaccurate"); log.debug(Util.stackTrace(e)); } }
From source file:com.microsoft.alm.client.utils.JsonHelper.java
@SuppressWarnings("unchecked") public static <T> T deserializeResponce(final HttpMethodBase response, final Class<T> clazz) { try {/*from ww w .jav a 2 s . c o m*/ if (!InputStream.class.isAssignableFrom(clazz)) { final byte[] input = response.getResponseBody(); if (input == null || input.length == 0) { return null; } return objectMapper.readValue(input, clazz); } else if (response.getResponseContentLength() == 0) { return null; } else { final InputStream responseStream = response.getResponseBodyAsStream(); final Header contentTypeHeader = response.getResponseHeader(VssHttpHeaders.CONTENT_TYPE); if (contentTypeHeader != null && contentTypeHeader.getValue().equalsIgnoreCase(DownloadContentTypes.APPLICATION_GZIP)) { return (T) new GZIPInputStream(responseStream); } else { return (T) responseStream; } } } catch (final IOException e) { log.error(e.getMessage(), e); throw new VssServiceException(e.getMessage(), e); } finally { response.releaseConnection(); } }
From source file:com.hx.template.http.volley.BaseJsonObjectRequest.java
private String decodeGZip(byte[] data) { InputStream in;// w w w . ja v a 2s . com StringBuilder sb = new StringBuilder(); try { ByteArrayInputStream bis = new ByteArrayInputStream(data); in = new GZIPInputStream(bis); BufferedReader r = new BufferedReader(new InputStreamReader(in), 1000); for (String line = r.readLine(); line != null; line = r.readLine()) { sb.append(line); } in.close(); } catch (Exception e) { e.printStackTrace(); } return sb.toString(); }
From source file:eu.delving.sip.files.FileImporter.java
@Override public void run() { int fileBlocks = (int) (inputFile.length() / BLOCK_SIZE); progressListener.prepareFor(fileBlocks); try {/*from ww w.j ava2s. co m*/ OutputStream outputStream = new GZIPOutputStream(new FileOutputStream(dataSet.importedOutput())); InputStream inputStream = new FileInputStream(inputFile); inputStream = countingInputStream = new CountingInputStream(inputStream); try { String name = inputFile.getName(); if (name.endsWith(".csv")) { consumeCSVFile(inputStream, outputStream); } else if (name.endsWith(".xml.zip")) { consumeXMLZipFile(inputStream, outputStream); } else if (name.endsWith(".xml") || name.endsWith(".xml.gz")) { if (name.endsWith(".xml.gz")) inputStream = new GZIPInputStream(inputStream); consumeXMLFile(inputStream, outputStream); } else { throw new IllegalArgumentException("Unrecognized file extension: " + name); } } finally { IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(inputStream); } delete(statsFile(dataSet.importedOutput().getParentFile(), false, null)); if (finished != null) finished.run(); } catch (CancelException e) { delete(dataSet.importedOutput()); progressListener.getFeedback().alert("Cancelled", e); } catch (IOException e) { delete(dataSet.importedOutput()); progressListener.getFeedback().alert("Unable to import: " + e.getMessage(), e); } }
From source file:com.sap.nwcloudmanager.api.LogAPI.java
public static void downloadLog(final Context context, final String appId, final String logName, final DownloadLogResponseHandler downloadLogResponseHandler) { NetWeaverCloudConfig config = NetWeaverCloudConfig.getInstance(); getHttpClient().setBasicAuth(config.getUsername(), config.getPassword()); String[] contentTypes = { "application/x-gzip" }; getHttpClient().get("https://monitoring." + config.getHost() + "/log/api_basic/logs/" + config.getAccount() + "/" + appId + "/web/" + logName, null, new BinaryHttpResponseHandler(contentTypes) { /*/* w w w . j a va2s . co m*/ * (non-Javadoc) * * @see * com.loopj.android.http.BinaryHttpResponseHandler#onSuccess(byte * []) */ @Override public void onSuccess(byte[] arg0) { GZIPInputStream gzis = null; try { gzis = new GZIPInputStream(new ByteArrayInputStream(arg0)); StringBuilder string = new StringBuilder(); byte[] data = new byte[4028]; int bytesRead; while ((bytesRead = gzis.read(data)) != -1) { string.append(new String(data, 0, bytesRead)); } File downloadsFile = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); if (downloadsFile.exists()) { downloadsFile = new File( context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) .getAbsolutePath() + "/" + logName); FileOutputStream fos = new FileOutputStream(downloadsFile); fos.write(string.toString().getBytes()); fos.close(); } downloadLogResponseHandler.onSuccess(downloadsFile.getAbsolutePath()); } catch (IOException e) { Log.e(e.getMessage()); } finally { try { if (gzis != null) { gzis.close(); } } catch (IOException e) { } } } @Override public void onFailure(Throwable arg0) { downloadLogResponseHandler.onFailure(arg0, arg0.getMessage()); } }); }
From source file:uk.ac.cam.cl.dtg.picky.parser.pcap2.PcapParser.java
@Override public void open(File file) throws IOException { this.file = file; LOG.info("opening " + file); tmpFolder.mkdirs();/* ww w . j a v a2s . c o m*/ try { if (file.getName().toLowerCase().endsWith(".gz")) { LOG.info("decompressing " + file); tempFile = new File(tmpFolder, file.getName() + ".tmp"); tempFile.delete(); tempFile.deleteOnExit(); GZIPInputStream stream = new GZIPInputStream(new BufferedInputStream(new FileInputStream(file))); FileUtils.copyInputStreamToFile(stream, tempFile); stream.close(); pcap = Pcaps.openOffline(tempFile.getAbsolutePath()); } else { pcap = Pcaps.openOffline(file.getAbsolutePath()); } globalHeader = readGlobalHeader(file); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.mashape.unirest.android.http.HttpResponse.java
@SuppressWarnings("unchecked") public HttpResponse(org.apache.http.HttpResponse response, Class<T> responseClass) { HttpEntity responseEntity = response.getEntity(); ObjectMapper objectMapper = (ObjectMapper) Options.getOption(Option.OBJECT_MAPPER); Header[] allHeaders = response.getAllHeaders(); for (Header header : allHeaders) { String headerName = header.getName(); List<String> list = headers.get(headerName); if (list == null) list = new ArrayList<String>(); list.add(header.getValue());//from w w w.j a v a 2 s . c o m headers.put(headerName, list); } StatusLine statusLine = response.getStatusLine(); this.statusCode = statusLine.getStatusCode(); this.statusText = statusLine.getReasonPhrase(); if (responseEntity != null) { String charset = "UTF-8"; Header contentType = responseEntity.getContentType(); if (contentType != null) { String responseCharset = ResponseUtils.getCharsetFromContentType(contentType.getValue()); if (responseCharset != null && !responseCharset.trim().equals("")) { charset = responseCharset; } } try { byte[] rawBody; try { InputStream responseInputStream = responseEntity.getContent(); if (ResponseUtils.isGzipped(responseEntity.getContentEncoding())) { responseInputStream = new GZIPInputStream(responseEntity.getContent()); } rawBody = ResponseUtils.getBytes(responseInputStream); } catch (IOException e2) { throw new RuntimeException(e2); } this.rawBody = new ByteArrayInputStream(rawBody); if (JsonNode.class.equals(responseClass)) { String jsonString = new String(rawBody, charset).trim(); this.body = (T) new JsonNode(jsonString); } else if (String.class.equals(responseClass)) { this.body = (T) new String(rawBody, charset); } else if (InputStream.class.equals(responseClass)) { this.body = (T) this.rawBody; } else if (objectMapper != null) { this.body = objectMapper.readValue(new String(rawBody, charset), responseClass); } else { throw new Exception( "Only String, JsonNode and InputStream are supported, or an ObjectMapper implementation is required."); } } catch (Exception e) { throw new RuntimeException(e); } } //EntityUtils.consumeQuietly(responseEntity); }