Package org.apache.commons.compress.compressors.gzip

Examples of org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream


  public static boolean hasGitFolder(InputStream inputStream) throws IOException {
    TarArchiveInputStream tarInputStream = null;
    try {
      boolean gitFolderPresent = false;
      tarInputStream = new TarArchiveInputStream(new GzipCompressorInputStream(inputStream));
      for (TarArchiveEntry entry = null; (entry = tarInputStream.getNextTarEntry()) != null;) {
        if (GIT_FOLDER_NAME.equals(entry.getName())
            && entry.isDirectory()) {
          gitFolderPresent = true;
          break;
View Full Code Here


            if (Files.notExists(destDir)) {
                logger.trace("Create dir: {}", destDir);
                Files.createDirectories(destDir);
            }

            TarArchiveInputStream in = new TarArchiveInputStream(new GzipCompressorInputStream(Files.newInputStream(tgzFile)));

            TarArchiveEntry entry;
            while ((entry = in.getNextTarEntry()) != null) {
                if (entry.isDirectory()) {
                    Path dir = destDir.resolve(entry.getName());
View Full Code Here

    public void readFileBiggerThan8GBytePosix() throws Exception {
        readFileBiggerThan8GByte("/8.posix.tar.gz");
    }

    private void readFileBiggerThan8GByte(String name) throws Exception {
        GzipCompressorInputStream in = null;
        TarArchiveInputStream tin = null;
        try {
            in =
                new GzipCompressorInputStream(BigFilesIT.class
                                              .getResourceAsStream(name));
            tin = new TarArchiveInputStream(in);
            TarArchiveEntry e = tin.getNextTarEntry();
            assertNotNull(e);
            assertEquals(8200l * 1024 * 1024, e.getSize());

            long read = 0;
            Random r = new Random(System.currentTimeMillis());
            int readNow;
            byte[] buf = new byte[1024 * 1024];
            while ((readNow = tin.read(buf, 0, buf.length)) > 0) {
                // testing all bytes for a value of 0 is going to take
                // too long, just pick a few ones randomly
                for (int i = 0; i < 100; i++) {
                    int idx = r.nextInt(readNow);
                    assertEquals("testing byte " + (read + idx), 0, buf[idx]);
                }
                read += readNow;
            }
            assertEquals(8200l * 1024 * 1024, read);
            assertNull(tin.getNextTarEntry());
        } finally {
            if (tin != null) {
                tin.close();
            }
            if (in != null) {
                in.close();
            }
        }
    }
View Full Code Here

        final RequestIdentifier identifier = new RequestIdentifier(newUri);
        final RequestMetaData metaData = new RequestMetaData(SIZE, TIME, uri.getPath());
        final GZipIdentificationRequest gzRequest = new GZipIdentificationRequest(
                metaData, identifier, tmpDir);

        GzipCompressorInputStream gzin = null;
        try {
            gzin = new GzipCompressorInputStream(
                new FileInputStream(request.getSourceFile()));

            gzRequest.open(gzin);
            final IdentificationResultCollection gzResults =
                     binarySignatureIdentifier.matchBinarySignatures(gzRequest);
           
            final ResultPrinter resultPrinter = new ResultPrinter(binarySignatureIdentifier,
                    containerSignatureDefinitions, newPath, slash, slash1, true);
            resultPrinter.print(gzResults, gzRequest);
        } catch (IOException ioe) {
            System.err.println(ioe + " (" + newPath + ")"); // continue after corrupt archive
        } finally {
            if (gzin != null) {
                try {
                    gzin.close();
                } catch (IOException ioe) {
                    throw new CommandExecutionException(ioe.getMessage(), ioe);
                }
            }
        }
View Full Code Here

            if (Files.notExists(destDir)) {
                logger.trace("Create dir: {}", destDir);
                Files.createDirectories(destDir);
            }

            TarArchiveInputStream in = new TarArchiveInputStream(new GzipCompressorInputStream(Files.newInputStream(tgzFile)));

            TarArchiveEntry entry;
            while ((entry = in.getNextTarEntry()) != null) {
                if (entry.isDirectory()) {
                    Path dir = destDir.resolve(entry.getName());
View Full Code Here

                extractArchive(new TarArchiveInputStream(new BufferedInputStream(fis)), destination, engine);
            } else if ("gz".equals(archiveExt) || "tgz".equals(archiveExt)) {
                final String uncompressedName = GzipUtils.getUncompressedFilename(archive.getName());
                final String uncompressedExt = FileUtils.getFileExtension(uncompressedName).toLowerCase();
                if (engine.supportsExtension(uncompressedExt)) {
                    decompressFile(new GzipCompressorInputStream(new BufferedInputStream(fis)), new File(destination, uncompressedName));
                }
            }
        } catch (ArchiveExtractionException ex) {
            final String msg = String.format("Exception extracting archive '%s'.", archive.getName());
            LOGGER.log(Level.WARNING, msg);
View Full Code Here

    }

    private static void extractGzArchive(InputStream tarGz, File tar) throws IOException {
        BufferedInputStream in = new BufferedInputStream(tarGz);
        FileOutputStream out = new FileOutputStream(tar);
        GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
        final byte[] buffer = new byte[1000];
        int n = 0;
        while (-1 != (n = gzIn.read(buffer))) {
            out.write(buffer, 0, n);
        }
        out.close();
        gzIn.close();
    }
View Full Code Here

     * @throws IOException When a problem occurs with either the input or output stream
     */
    public static File uncompressGzipArchive(File archiveFile, File outputDirectory) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(archiveFile);
        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
        GzipCompressorInputStream gzipInputStream = new GzipCompressorInputStream(bufferedInputStream);

        String tarArchiveFilename = GzipUtils.getUncompressedFilename(archiveFile.getName());
        File outputFile = new File(outputDirectory, tarArchiveFilename);
        FileOutputStream outputStream = new FileOutputStream(outputFile);

        int byteReadCount = 0;
        final byte[] data = new byte[BUFFER_SIZE];

        try {
            while ((byteReadCount = gzipInputStream.read(data, 0, BUFFER_SIZE)) != -1) {
                outputStream.write(data, 0, byteReadCount);
            }
        } finally {
            outputStream.close();
            gzipInputStream.close();
        }

        return outputFile;
    }
View Full Code Here

            if (BZip2CompressorInputStream.matches(signature, signatureLength)) {
                return new BZip2CompressorInputStream(in, decompressConcatenated);
            }

            if (GzipCompressorInputStream.matches(signature, signatureLength)) {
                return new GzipCompressorInputStream(in, decompressConcatenated);
            }

            if (XZUtils.isXZCompressionAvailable() &&
                XZCompressorInputStream.matches(signature, signatureLength)) {
                return new XZCompressorInputStream(in, decompressConcatenated);
View Full Code Here

        }

        try {

            if (GZIP.equalsIgnoreCase(name)) {
                return new GzipCompressorInputStream(in, decompressConcatenated);
            }

            if (BZIP2.equalsIgnoreCase(name)) {
                return new BZip2CompressorInputStream(in, decompressConcatenated);
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.