List of usage examples for java.util.zip GZIPInputStream GZIPInputStream
public GZIPInputStream(InputStream in) throws IOException
From source file:com.arpnetworking.metrics.mad.performance.CollectdPipelinePT.java
@BeforeClass public static void setUp() throws IOException, URISyntaxException { // Extract the sample file final Path gzipPath = Paths.get(Resources.getResource("collectd-sample1.log.gz").toURI()); final FileInputStream fileInputStream = new FileInputStream(gzipPath.toFile()); final GZIPInputStream gzipInputStream = new GZIPInputStream(fileInputStream); final Path path = Paths.get("target/tmp/perf/collectd-sample1.log"); final FileOutputStream outputStream = new FileOutputStream(path.toFile()); IOUtils.copy(gzipInputStream, outputStream); JSON_BENCHMARK_CONSUMER.prepareClass(); }
From source file:edu.ucla.cs.scai.swim.qa.ontology.dbpedia.tipicality.DbpediaCategoryAttributeCounts.java
private static void processFile(File csvData, String category) throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(csvData)))); //CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), CSVFormat.RFC4180); CSVParser parser = CSVFormat.EXCEL.parse(in); int r = 0;//from www .ja v a 2s . co m ArrayList<Integer> attributePositions = new ArrayList<>(); ArrayList<String> attributeNames = new ArrayList<>(); HashMap<String, Integer> thisCategoryAttributeCounts = new HashMap<>(); categoryAttributeCount.put(category, thisCategoryAttributeCounts); for (CSVRecord csvRecord : parser) { if (r == 0) { Iterator<String> it = csvRecord.iterator(); it.next(); //skip URI if (!it.hasNext()) { //it is an empty file return; } it.next(); //skip rdf-schema#label it.next(); //skip rdf-schema#comment int c = 2; for (; it.hasNext();) { c++; String attr = it.next(); if (!attr.endsWith("_label")) { attributePositions.add(c); } } categories.add(category); } else if (r == 1) { Iterator<String> it = csvRecord.iterator(); it.next(); //skip uri it.next(); //skip rdf-schema#label it.next(); //skip rdf-schema#comment int c = 2; int i = 0; while (i < attributePositions.size()) { c++; String attr = it.next(); if (attributePositions.get(i) == c) { if (!stopAttributes.contains(attr)) { attributes.add(attr); } attributeNames.add(attr); i++; } } } else if (r > 3) { Iterator<String> it = csvRecord.iterator(); String uri = it.next(); /*if (entities.contains(uri)) { System.out.println(uri + " already processed"); continue; }*/ entities.add(uri); it.next(); //skip rdf-schema#label it.next(); //skip rdf-schema#comment int c = 2; int i = 0; while (i < attributePositions.size()) { c++; String val = it.next(); if (attributePositions.get(i) == c) { if (!val.equalsIgnoreCase("null")) { String attribute = attributeNames.get(i); if (!stopAttributes.contains(attribute)) { Integer ac = attributeCount.get(attribute); if (ac == null) { attributeCount.put(attribute, 1); } else { attributeCount.put(attribute, ac + 1); } Integer tcac = thisCategoryAttributeCounts.get(attribute); if (tcac == null) { thisCategoryAttributeCounts.put(attribute, 1); } else { thisCategoryAttributeCounts.put(attribute, tcac + 1); } HashMap<String, Integer> thisAttributeCategoryCounts = attributeCategoryCount .get(attribute); if (thisAttributeCategoryCounts == null) { thisAttributeCategoryCounts = new HashMap<>(); attributeCategoryCount.put(attribute, thisAttributeCategoryCounts); } Integer tacc = thisAttributeCategoryCounts.get(category); if (tacc == null) { thisAttributeCategoryCounts.put(category, 1); } else { thisAttributeCategoryCounts.put(category, tacc + 1); } } } i++; } } } r++; } categoryCount.put(category, r - 3); }
From source file:edu.umd.umiacs.clip.tools.io.GZIPFiles.java
public static List<String> readAllLines(Path path) throws IOException { try (BufferedReader reader = new BufferedReader(new InputStreamReader( new GZIPInputStream(new BufferedInputStream(newInputStream(path), BUFFER_SIZE)), UTF_8.newDecoder().onMalformedInput(IGNORE)))) { List<String> result = new ArrayList<>(); String line;//ww w.j a va2 s. co m while ((line = reader.readLine()) != null) { result.add(line); } return result; } }
From source file:me.xiaopan.android.gohttp.httpclient.InflatingEntity.java
@Override public InputStream getContent() throws IOException { return new GZIPInputStream(wrappedEntity.getContent()); }
From source file:bigfat.hadoop.HDFSDirInputStream.java
@Override protected InputStream getNextStream(String file) { try {//ww w . j av a2s .c om FSDataInputStream stream = fs.open(new Path(file)); if (file.endsWith(".gz")) { return new GZIPInputStream(stream); } else { return stream; } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:it.agileday.utils.HttpRestUtil.java
public static JSONObject httpGetJsonObject(String uri) { try {/*from w w w. ja v a2 s .co m*/ HttpGet httpGetRequest = new HttpGet(uri); httpGetRequest.setHeader("Accept", "application/json"); httpGetRequest.setHeader("Accept-Encoding", "gzip"); HttpResponse response = new DefaultHttpClient().execute(httpGetRequest); HttpEntity entity = response.getEntity(); JSONObject ret = null; if (entity != null) { InputStream stream = entity.getContent(); try { if (HttpRestUtil.isGzipEncoded(response)) { stream = new GZIPInputStream(stream); } String str = HttpRestUtil.convertStreamToString(stream); ret = new JSONObject(str); } finally { stream.close(); } } return ret; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * decompress a gzip byte array, using a default buffer length of 1024 * <p>//from w ww .j av a 2s .co m * @param compressedByteArray gzip-compressed byte array * @param bufferlength size of the buffer in bytes * @return decompressed byte array * @throws IOException thrown if there was a failure to construct the GzipInputStream */ public static byte[] decompressGzipByteArray(byte[] compressedByteArray, int bufferlength) throws IOException { ByteArrayOutputStream uncompressedStream = new ByteArrayOutputStream(); GZIPInputStream compressedStream = new GZIPInputStream(new ByteArrayInputStream(compressedByteArray)); byte[] buffer = new byte[bufferlength]; int index = -1; while ((index = compressedStream.read(buffer)) != -1) { uncompressedStream.write(buffer, 0, index); } return uncompressedStream.toByteArray(); }
From source file:com.sonatype.nexus.perftest.maven.CsvLogParser.java
@JsonCreator public CsvLogParser(@JsonProperty("logfile") File logfile) throws IOException { ArrayList<String> paths = new ArrayList<>(); try (BufferedReader br = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(logfile))))) { String str;/*from ww w . j a v a 2s .com*/ while ((str = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(str, ","); paths.add(st.nextToken()); // full path } } this.paths = Collections.unmodifiableList(paths); }
From source file:com.github.jrh3k5.mojo.flume.io.ArchiveUtils.java
/** * Un-GZIP a file.// w ww . j a v a 2 s. co m * * @param toUnzip * A {@link URL} representing the GZIP file to be unzipped. * @param toFile * A {@link File} representing the location to which the unzipped file should be placed. * @throws IOException * If any errors occur during the unzipping. * @see #gzipFile(File, File) */ public static void gunzipFile(URL toUnzip, File toFile) throws IOException { if (toFile.exists() && !toFile.isFile()) { throw new IllegalArgumentException("Destination file " + toFile + " exists, but is not a file and, as such, cannot be written to."); } GZIPInputStream zipIn = null; FileOutputStream fileOut = null; try { zipIn = new GZIPInputStream(toUnzip.openStream()); fileOut = new FileOutputStream(toFile); IOUtils.copy(zipIn, fileOut); } finally { IOUtils.closeQuietly(fileOut); IOUtils.closeQuietly(zipIn); } }
From source file:deployer.publishers.TarFileChecker.java
public void check(InputStream is) throws Exception { GZIPInputStream gzis = new GZIPInputStream(is); TarArchiveInputStream tarIs = new TarArchiveInputStream(gzis); check(tarIs);//from www . j a v a 2s .c o m }