Example usage for java.util.zip GZIPInputStream GZIPInputStream

List of usage examples for java.util.zip GZIPInputStream GZIPInputStream

Introduction

In this page you can find the example usage for java.util.zip GZIPInputStream GZIPInputStream.

Prototype

public GZIPInputStream(InputStream in) throws IOException 

Source Link

Document

Creates a new input stream with a default buffer size.

Usage

From source file:co.runrightfast.vertx.core.hazelcast.serializers.CompressedJsonObjectSerializer.java

@Override
public JsonObject read(final byte[] bytes) throws IOException {
    try (final JsonReader reader = Json.createReader(new GZIPInputStream(new ByteArrayInputStream(bytes)))) {
        return reader.readObject();
    }//from w w w.  j  a  va  2  s. c  o  m
}

From source file:ijfx.core.IjfxTest.java

public void displayFile(File file) throws IOException {

    System.out.println(file.toString());

    if (file.getName().endsWith(".gz")) {

        FileInputStream fis = new FileInputStream(file);

        GZIPInputStream gis = new GZIPInputStream(fis);

        Reader decoder = new InputStreamReader(gis, "utf-8");
        BufferedReader buffered = new BufferedReader(decoder);
        String line = buffered.readLine();
        while (line != null) {
            System.out.println(line);
            line = buffered.readLine();/*from ww  w. j  ava 2  s. c o m*/
        }

    } else {

        System.out.println(FileUtils.readFileToString(file));
    }
}

From source file:de.tudarmstadt.ukp.csniper.resbuild.stuff.CasFlusher.java

public static void flush(File aSerializedCas, OutputStream aOutputStream, int aBegin, int aEnd)
        throws IOException {
    CAS cas = new CASImpl();

    InputStream is = null;/*w  w w.j  a  v  a2  s.c om*/
    try {
        is = new FileInputStream(aSerializedCas);
        if (aSerializedCas.getName().endsWith(".gz")) {
            is = new GZIPInputStream(is);
        } else if (aSerializedCas.getName().endsWith(".xz")) {
            is = new XZInputStream(is);
        }
        is = new ObjectInputStream(new BufferedInputStream(is));
        CASCompleteSerializer serializer = (CASCompleteSerializer) ((ObjectInputStream) is).readObject();

        ((CASImpl) cas).reinit(serializer);
    } catch (ClassNotFoundException e) {
        throw new IOException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }

    Collection<AnnotationFS> annos;
    if (aBegin > -1 && aEnd > -1) {
        annos = CasUtil.selectCovered(cas, CasUtil.getType(cas, Annotation.class), aBegin, aEnd);
    } else {
        annos = CasUtil.selectAll(cas);
    }
    for (AnnotationFS anno : annos) {
        StringBuilder sb = new StringBuilder();
        sb.append("[" + anno.getClass().getSimpleName() + "] ");
        sb.append("(" + anno.getBegin() + "," + anno.getEnd() + ") ");
        sb.append(anno.getCoveredText() + "\n");
        IOUtils.write(sb, aOutputStream, "UTF-8");
    }
}

From source file:it.unimi.dsi.sux4j.mph.VLPaCoTrieDistributorMonotoneMinimalPerfectHashFunction.java

public static void main(final String[] arg) throws NoSuchMethodException, IOException, JSAPException {

    final SimpleJSAP jsap = new SimpleJSAP(
            VLPaCoTrieDistributorMonotoneMinimalPerfectHashFunction.class.getName(),
            "Builds a variable-length PaCo trie-based monotone minimal perfect hash function reading a newline-separated list of strings.",
            new Parameter[] {
                    new FlaggedOption("encoding", ForNameStringParser.getParser(Charset.class), "UTF-8",
                            JSAP.NOT_REQUIRED, 'e', "encoding", "The string file encoding."),
                    new Switch("huTucker", 'h', "hu-tucker", "Use Hu-Tucker coding to reduce string length."),
                    new Switch("iso", 'i', "iso",
                            "Use ISO-8859-1 coding internally (i.e., just use the lower eight bits of each character)."),
                    new Switch("utf32", JSAP.NO_SHORTFLAG, "utf-32",
                            "Use UTF-32 internally (handles surrogate pairs)."),
                    new Switch("zipped", 'z', "zipped", "The string list is compressed in gzip format."),
                    new UnflaggedOption("function", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED,
                            JSAP.NOT_GREEDY,
                            "The filename for the serialised monotone minimal perfect hash function."),
                    new UnflaggedOption("stringFile", JSAP.STRING_PARSER, "-", JSAP.NOT_REQUIRED,
                            JSAP.NOT_GREEDY,
                            "The name of a file containing a newline-separated list of strings, or - for standard input; in the first case, strings will not be loaded into core memory."), });

    JSAPResult jsapResult = jsap.parse(arg);
    if (jsap.messagePrinted())
        return;//from  w w w.  java  2 s  .  c o  m

    final String functionName = jsapResult.getString("function");
    final String stringFile = jsapResult.getString("stringFile");
    final Charset encoding = (Charset) jsapResult.getObject("encoding");
    final boolean zipped = jsapResult.getBoolean("zipped");
    final boolean iso = jsapResult.getBoolean("iso");
    final boolean utf32 = jsapResult.getBoolean("utf32");
    final boolean huTucker = jsapResult.getBoolean("huTucker");

    final Collection<MutableString> collection;
    if ("-".equals(stringFile)) {
        final ProgressLogger pl = new ProgressLogger(LOGGER);
        pl.displayLocalSpeed = true;
        pl.displayFreeMemory = true;
        pl.start("Loading strings...");
        collection = new LineIterator(
                new FastBufferedReader(
                        new InputStreamReader(zipped ? new GZIPInputStream(System.in) : System.in, encoding)),
                pl).allLines();
        pl.done();
    } else
        collection = new FileLinesCollection(stringFile, encoding.toString(), zipped);
    final TransformationStrategy<CharSequence> transformationStrategy = huTucker
            ? new HuTuckerTransformationStrategy(collection, true)
            : iso ? TransformationStrategies.prefixFreeIso()
                    : utf32 ? TransformationStrategies.prefixFreeUtf32()
                            : TransformationStrategies.prefixFreeUtf16();

    BinIO.storeObject(new VLPaCoTrieDistributorMonotoneMinimalPerfectHashFunction<CharSequence>(collection,
            transformationStrategy), functionName);
    LOGGER.info("Completed.");
}

From source file:com.arpnetworking.tsdaggregator.perf.CollectdPipelineTest.java

@Test
public void test() throws IOException, InterruptedException, URISyntaxException {
    // Extract the sample file

    final Path gzipPath = Paths.get("build/resources/perf/collectd-sample1.log.gz");
    final FileInputStream fileInputStream = new FileInputStream(gzipPath.toFile());
    final GZIPInputStream gzipInputStream = new GZIPInputStream(fileInputStream);
    final Path path = Paths.get("build/tmp/perf/collectd-sample1.log");
    final FileOutputStream outputStream = new FileOutputStream(path.toFile());

    IOUtils.copy(gzipInputStream, outputStream);

    benchmark(new File(Resources.getResource("collectd_sample1_pipeline.json").toURI()),
            Duration.standardMinutes(20));
}

From source file:metadata.etl.lineage.AzDbCommunicator.java

public String getExecLog(long execId, String jobName) throws SQLException, IOException {
    System.out.println("start");
    String cmd = "select log from execution_logs where exec_id = " + execId + " and name = '" + jobName
            + "'and attempt = 0 order by start_byte;";
    System.out.println(cmd);/*  w w  w  .ja v a2 s .co  m*/
    Statement statement = conn.createStatement();
    ResultSet rs = statement.executeQuery(cmd);
    StringBuilder sb = new StringBuilder();
    while (rs.next()) {
        Blob logBlob = rs.getBlob("log");
        GZIPInputStream gzip = new GZIPInputStream(logBlob.getBinaryStream());
        sb.append(IOUtils.toString(gzip, "UTF-8"));
    }
    statement.close();
    System.out.println("stop");
    return sb.toString();
}

From source file:com.suning.mobile.ebuy.lottery.network.util.GzipDecompressingEntity.java

/**
 * //  w w w.j a v a 2s.  c  o m
 */
public InputStream getContent() throws IOException, IllegalStateException {

    // the wrapped entity's getContent() decides about repeatability
    InputStream wrappedin = wrappedEntity.getContent();
    return new GZIPInputStream(wrappedin);
}

From source file:com.ontologycentral.ldspider.http.internal.GzipDecompressingEntity.java

public InputStream getContent() throws IOException, IllegalStateException {

    // the wrapped entity's getContent() decides about repeatability
    InputStream wrappedin = wrappedEntity.getContent();

    return new GZIPInputStream(wrappedin);
}

From source file:ch.ledcom.jpreseed.InitrdRepacker.java

public final void repack(OutputStream out) throws IOException {
    // start new archive
    try (CpioArchiveInputStream cpioIn = new CpioArchiveInputStream(new GZIPInputStream(initrdGz));
            CpioArchiveOutputStream cpioOut = new CpioArchiveOutputStream(new GZIPOutputStream(out))) {
        CpioArchiveEntry cpioEntry;/*from  w  w w.j a v  a2s .  c om*/

        // add files from base archive
        while ((cpioEntry = cpioIn.getNextCPIOEntry()) != null) {
            if (!additionalFiles.keySet().contains(cpioEntry.getName())) {
                logger.info("Repacking [{}]", cpioEntry.getName());
                cpioOut.putArchiveEntry(cpioEntry);
                long bytesCopied = copy(cpioIn, cpioOut);
                cpioOut.closeArchiveEntry();
                logger.debug("Copied [{}] bytes", bytesCopied);
            }
        }

        // additional files
        for (Map.Entry<String, File> entry : additionalFiles.entrySet()) {
            logger.info("Packing new file [{}]", entry.getKey());
            ArchiveEntry additionalEntry = cpioOut.createArchiveEntry(entry.getValue(), entry.getKey());
            cpioOut.putArchiveEntry(additionalEntry);
            try (InputStream in = new FileInputStream(entry.getValue())) {
                copy(in, cpioOut);
            }
            cpioOut.closeArchiveEntry();
        }
    }
}

From source file:org.apache.juneau.rest.test.GzipTest.java

private static String decompress(InputStream is) throws Exception {
    return IOUtils.read(new GZIPInputStream(is));
}