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:com.melniqw.instagramsdk.Network.java

private static String sendDummyRequest(String url, String body, Request request) throws IOException {
    HttpURLConnection connection = null;
    try {//from w w  w  . j  a  v a  2s  .c o m
        connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setConnectTimeout(10000);
        connection.setReadTimeout(10000);
        connection.setUseCaches(false);
        connection.setDoInput(true);
        //            connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
        if (request == Request.GET) {
            connection.setDoOutput(false);
            connection.setRequestMethod("GET");
        } else if (request == Request.POST) {
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
        }
        if (REQUEST_ENABLE_COMPRESSION)
            connection.setRequestProperty("Accept-Encoding", "gzip");
        if (request == Request.POST)
            connection.getOutputStream().write(body.getBytes("utf-8"));
        int code = connection.getResponseCode();
        System.out.println(TAG + " responseCode = " + code);
        //It may happen due to keep-alive problem http://stackoverflow.com/questions/1440957/httpurlconnection-getresponsecode-returns-1-on-second-invocation
        if (code == -1)
            throw new WrongResponseCodeException("Network error");
        // ?    200
        //on error can also read error stream from connection.
        InputStream inputStream = new BufferedInputStream(connection.getInputStream(), 8192);
        String encoding = connection.getHeaderField("Content-Encoding");
        if (encoding != null && encoding.equalsIgnoreCase("gzip"))
            inputStream = new GZIPInputStream(inputStream);
        String response = Utils.convertStreamToString(inputStream);
        System.out.println(TAG + " response = " + response);
        return response;
    } finally {
        if (connection != null)
            connection.disconnect();
    }
}

From source file:HLA.java

private boolean checkHeader(SAMFileHeader header) {
    List<SAMSequenceRecord> sequences = header.getSequenceDictionary().getSequences();
    HashSet<String> map = new HashSet<String>();

    //load kourami panel sequence names
    BufferedReader br;/*from www  .  ja  va2s  .  c o m*/
    try {
        br = new BufferedReader(new InputStreamReader(new GZIPInputStream(
                new FileInputStream(HLA.MSAFILELOC + File.separator + "All_FINAL_with_Decoy.fa.gz"))));
        String curline = "";
        while ((curline = br.readLine()) != null) {
            if (curline.charAt(0) == ('>'))
                map.add(curline.substring(1));
        }
        br.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

    //check if input bam has sequences to kourami panel
    for (SAMSequenceRecord ssr : sequences) {
        if (!map.contains(ssr.getSequenceName()))
            return false;
    }
    return true;
}

From source file:eu.europeana.uim.sugarcrmclient.internal.ExtendedSaajSoapMessageFactory.java

/**
 * Detects if the incoming stream is Gzip encoded
 * /*from w  w  w.  ja v  a  2  s  . c o  m*/
 * @param pb
 * @return an InputStream/GZIPInputStream 
 * @throws IOException
 */
public static InputStream decompressStream(PushbackInputStream pb) throws IOException {
    byte[] signature = new byte[2];
    pb.read(signature);
    pb.unread(signature);

    if (signature[0] == 31 && signature[1] == -117)
        return new GZIPInputStream(pb);
    else
        return pb;
}

From source file:uk.ac.ebi.eva.pipeline.jobs.steps.VariantLoaderStepTest.java

@Test
public void loaderStepShouldLoadAllVariants() throws Exception {
    Config.setOpenCGAHome(opencgaHome);/*from   w  ww.  j a  va 2  s .  c  o m*/

    jobOptions.getVariantOptions().put(VariantStorageManager.DB_NAME, dbName);
    jobOptions.getVariantOptions().put(VARIANT_SOURCE, new VariantSource(input, "1", "1", "studyName",
            VariantStudy.StudyType.COLLECTION, VariantSource.Aggregation.NONE));

    //and a variants transform step already executed
    File transformedVcfVariantsFile = new File(
            VariantLoaderStepTest.class.getResource("/small20.vcf.gz.variants.json.gz").getFile());
    File tmpTransformedVcfVariantsFile = new File(outputDir, transformedVcfVariantsFile.getName());
    FileUtils.copyFile(transformedVcfVariantsFile, tmpTransformedVcfVariantsFile);

    File transformedVariantsFile = new File(
            VariantLoaderStepTest.class.getResource("/small20.vcf.gz.file.json.gz").getFile());
    File tmpTransformedVariantsFile = new File(outputDir, transformedVariantsFile.getName());
    FileUtils.copyFile(transformedVariantsFile, tmpTransformedVariantsFile);

    // When the execute method in variantsLoad is executed
    JobExecution jobExecution = jobLauncherTestUtils.launchStep(GenotypedVcfJob.LOAD_VARIANTS);

    //Then variantsLoad step should complete correctly
    assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

    // And the number of documents in db should be the same number of line of the vcf transformed file
    VariantStorageManager variantStorageManager = StorageManagerFactory.getVariantStorageManager();
    VariantDBAdaptor variantDBAdaptor = variantStorageManager.getDBAdaptor(dbName, null);
    VariantDBIterator iterator = variantDBAdaptor.iterator(new QueryOptions());
    long lines = getLines(new GZIPInputStream(new FileInputStream(transformedVcfVariantsFile)));

    assertEquals(count(iterator), lines);

    tmpTransformedVcfVariantsFile.delete();
    tmpTransformedVariantsFile.delete();
}

From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java

public static void checkUpdateVOMSConfigFiles() throws IOException {
    refreshVOMSConfig();//  w w w. ja  v  a 2 s  .  c  o m
    if (!(new File(vomslocation).exists())) {
        boolean success = (new File(vomslocation).mkdir());
        if (!success) {
            throw new IOException("Couldn't create directory for VOMS support: " + vomslocation);
        }
    }
    if (!new File(vomslocation).isDirectory()) {
        throw new IOException("Location: " + vomslocation + " is not a directory");
    } else {

        URL vomsURL = new URL(vomsConfigURL);
        InputStream in;
        try {
            in = new GZIPInputStream(vomsURL.openStream());

        } catch (FileNotFoundException fnf) {
            throw new IOException("URL: " + vomslocation + " does not exists.");
        } catch (IOException ioe) {
            throw new IOException(
                    "Failed to download VOMS config '" + vomsConfigURL + "'.\n" + ioe.getMessage());
        }

        try {
            untar(in, vomslocation);
        } catch (IOException ioe) {
            throw new IOException("Untarring VOMS config into '" + vomslocation + "'.\n" + ioe.getMessage());
        }
    }

    //Favourites
    if (!(new File(favouritesFile).exists())) {
        boolean success = (new File(favouritesFile).createNewFile());
        if (!success) {
            throw new IOException(
                    "Couldn't create 'Favourites' directory to allow you to store your VOs: " + favouritesFile);
        }
    }
    try {
        Chmod(true, "755", vomslocation);
    } catch (IOException ioe) {
        throw new IOException("Cannot change directory permission of " + vomslocation + ".");
    }

}

From source file:com.twentyn.patentExtractor.Util.java

public static Document decompressXMLDocument(byte[] bytes) throws IOException, ParserConfigurationException,
        SAXException, TransformerConfigurationException, TransformerException {
    // With help from http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    InputStream s = new GZIPInputStream(new Base64InputStream(bais));
    DocumentBuilder documentBuilder = mkDocBuilderFactory().newDocumentBuilder();
    Document doc = documentBuilder.parse(s);
    s.close();//from w  ww. ja v  a2s . c o m
    return doc;
}

From source file:de.unidue.ltl.pos.trainmodel.misc.SharedTaskReader.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);

    posMappingProvider = new MappingProvider();
    posMappingProvider.setDefault(MappingProvider.LOCATION, "classpath:/de/tudarmstadt/ukp/dkpro/"
            + "core/api/lexmorph/tagset/${language}-${tagger.tagset}-pos.map");
    posMappingProvider.setDefault(MappingProvider.BASE_TYPE, POS.class.getName());
    posMappingProvider.setDefault("tagger.tagset", "default");
    posMappingProvider.setOverride(MappingProvider.LOCATION, mappingPosLocation);
    posMappingProvider.setOverride(MappingProvider.LANGUAGE, language);
    posMappingProvider.setOverride("tagger.tagset", posTagset);

    try {/*  ww  w.j  a  v  a  2 s  . c o m*/
        for (Resource r : getResources()) {
            String name = r.getResource().getFile().getName();
            InputStreamReader is = null;
            if (name.endsWith(".gz")) {
                is = new InputStreamReader(new GZIPInputStream(r.getInputStream()), encoding);
            } else {
                is = new InputStreamReader(r.getInputStream(), encoding);
            }
            br = new BufferedReader(is);
            bfs.add(br);
        }
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.evilisn.DAO.CertMapper.java

public static byte[] httpGetBin(URI uri, boolean bActiveCheckUnknownHost) throws Exception

{

    InputStream is = null;/*from   www. j a v  a 2 s. co  m*/

    InputStream is_temp = null;

    try {

        if (uri == null)
            return null;

        URL url = uri.toURL();

        if (bActiveCheckUnknownHost) {

            url.getProtocol();

            String host = url.getHost();

            int port = url.getPort();

            if (port == -1)

                port = url.getDefaultPort();

            InetSocketAddress isa = new InetSocketAddress(host, port);

            if (isa.isUnresolved()) {

                //fix JNLP popup error issue

                throw new UnknownHostException("Host Unknown:" + isa.toString());

            }

        }

        HttpURLConnection uc = (HttpURLConnection) url.openConnection();

        uc.setDoInput(true);

        uc.setAllowUserInteraction(false);

        uc.setInstanceFollowRedirects(true);

        setTimeout(uc);

        String contentEncoding = uc.getContentEncoding();

        int len = uc.getContentLength();

        // is = uc.getInputStream();

        if (contentEncoding != null && contentEncoding.toLowerCase().indexOf("gzip") != -1)

        {

            is_temp = uc.getInputStream();

            is = new GZIPInputStream(is_temp);

        }

        else if (contentEncoding != null && contentEncoding.toLowerCase().indexOf("deflate") != -1)

        {

            is_temp = uc.getInputStream();

            is = new InflaterInputStream(is_temp);

        }

        else

        {

            is = uc.getInputStream();

        }

        if (len != -1) {

            int ch = 0, i = 0;

            byte[] res = new byte[len];

            while ((ch = is.read()) != -1) {

                res[i++] = (byte) (ch & 0xff);

            }

            return res;

        } else {

            ArrayList<byte[]> buffer = new ArrayList<byte[]>();

            int buf_len = 1024;

            byte[] res = new byte[buf_len];

            int ch = 0, i = 0;

            while ((ch = is.read()) != -1) {

                res[i++] = (byte) (ch & 0xff);

                if (i == buf_len) {

                    //rotate

                    buffer.add(res);

                    i = 0;

                    res = new byte[buf_len];

                }

            }

            int total_len = buffer.size() * buf_len + i;

            byte[] buf = new byte[total_len];

            for (int j = 0; j < buffer.size(); j++) {

                System.arraycopy(buffer.get(j), 0, buf, j * buf_len, buf_len);

            }

            if (i > 0) {

                System.arraycopy(res, 0, buf, buffer.size() * buf_len, i);

            }

            return buf;

        }

    } catch (Exception e) {

        e.printStackTrace();

        return null;

    } finally {

        closeInputStream(is_temp);

        closeInputStream(is);

    }

}

From source file:ezbake.deployer.publishers.ezcentos.EzCentosThriftRunnerPublisher.java

/**
 * Copies files from the artifact .tar file
 * that end in the suffix to the specified destination.
 *
 * @param artifact// w w  w .ja  v a 2  s .c om
 * @param destination
 * @param suffix
 * @return Paths that the files were copied to
 * @throws IOException
 */
private List<String> copyFiles(DeploymentArtifact artifact, File destination, String suffix)
        throws IOException {
    TarArchiveInputStream tarIn = new TarArchiveInputStream(
            new GZIPInputStream(new ByteArrayInputStream(artifact.getArtifact())));
    List<String> filePaths = new ArrayList<>();
    try {
        TarArchiveEntry entry = tarIn.getNextTarEntry();

        while (entry != null) {
            if (entry.getName().endsWith(suffix)) {
                String newFilePath = destination + File.separator + entry.getName();
                FileOutputStream fos = new FileOutputStream(newFilePath);
                try {
                    IOUtils.copy(tarIn, fos);
                } finally {
                    IOUtils.closeQuietly(fos);
                }
                filePaths.add(newFilePath);
            }
            entry = tarIn.getNextTarEntry();
        }
    } finally {
        IOUtils.closeQuietly(tarIn);
    }

    return filePaths;
}