Package org.apache.commons.compress.archivers.tar

Examples of org.apache.commons.compress.archivers.tar.TarArchiveInputStream


  public void testTarDocPicture() throws Exception {
    Response response = WebClient.create(endPoint + UNPACKER_PATH)
        .type(APPLICATION_MSWORD).accept("application/x-tar")
        .put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV));

    Map<String, String> data = readArchive(new TarArchiveInputStream(
        (InputStream) response.getEntity()));

    assertEquals(JPG_MD5, data.get(JPG_NAME));
  }
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());
                    logger.trace("Create dir {}", dir);
                    Files.createDirectories(dir);
                } else {
                    Path file = destDir.resolve(entry.getName());
                    logger.trace("Create file {}: {} bytes", file, entry.getSize());
                    OutputStream out = Files.newOutputStream(file);
                    IOUtils.copy(in, out);
                    out.close();
                }
            }

            in.close();
        } catch (IOException e) {
            throw new RuntimeIOException("Exception expanding " + tgzFile + " to " + destDir, e);
        }
    }
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());
                    logger.trace("Create dir {}", dir);
                    Files.createDirectories(dir);
                } else {
                    Path file = destDir.resolve(entry.getName());
                    logger.trace("Create file {}: {} bytes", file, entry.getSize());
                    OutputStream out = Files.newOutputStream(file);
                    IOUtils.copy(in, out);
                    out.close();
                }
            }

            in.close();
        } catch (IOException e) {
            throw new RuntimeIOException("Exception expanding " + tgzFile + " to " + destDir, e);
        }
    }
View Full Code Here

        }
        if (ZIP.equalsIgnoreCase(archiverName)) {
            return new ZipArchiveInputStream(in);
        }
        if (TAR.equalsIgnoreCase(archiverName)) {
            return new TarArchiveInputStream(in);
        }
        if (JAR.equalsIgnoreCase(archiverName)) {
            return new JarArchiveInputStream(in);
        }
        if (CPIO.equalsIgnoreCase(archiverName)) {
View Full Code Here

            final byte[] tarheader = new byte[512];
            in.mark(tarheader.length);
            signatureLength = in.read(tarheader);
            in.reset();
            if (TarArchiveInputStream.matches(tarheader, signatureLength)) {
                return new TarArchiveInputStream(in);
            }
            // COMPRESS-117 - improve auto-recognition
            try {
                TarArchiveInputStream tais = new TarArchiveInputStream(new ByteArrayInputStream(tarheader));
                tais.getNextEntry();
                return new TarArchiveInputStream(in);
            } catch (Exception e) { // NOPMD
                // can generate IllegalArgumentException as well as IOException
                // autodetection, simply not a TAR
                // ignored
            }
View Full Code Here

    private void extractTarGzDistribution(URL sourceDistribution, File targetFolder) throws IOException,
            FileNotFoundException {
        File uncompressedFile = File.createTempFile("uncompressedTarGz-", ".tar");
        extractGzArchive(sourceDistribution.openStream(), uncompressedFile);
        extract(new TarArchiveInputStream(new FileInputStream(uncompressedFile)), targetFolder);
        FileUtils.forceDelete(uncompressedFile);
    }
View Full Code Here

    @Override
    public final void handle(IdentificationRequest request) throws IOException {

        InputStream tarIn = request.getSourceInputStream();
        try {
            final TarArchiveInputStream in = new TarArchiveInputStream(tarIn);
            try {               
                Iterable<TarArchiveEntry> iterable = new Iterable<TarArchiveEntry>() {
                    @Override
                    public final Iterator<TarArchiveEntry> iterator() {
                        return new TarArchiveEntryIterator(in);
                    }
                };
               
                TarArchiveWalker walker = new TarArchiveWalker(request.getIdentifier(), in);
                walker.walk(iterable);
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        } finally {
            if (tarIn != null) {
                tarIn.close();
View Full Code Here

        IdentificationRequestFactory factory = mock(IdentificationRequestFactory.class);

        // count the tar entries
        List<IdentificationRequest> mockRequests = new ArrayList<IdentificationRequest>();
        InputStream in = new FileInputStream(file);
        TarArchiveInputStream tarIn = new TarArchiveInputStream(in);
        ArchiveEntry entry;
        ResourceId expectedParentId = new ResourceId(99L, "");
        int count = 0;
        while ((entry = tarIn.getNextEntry()) != null) {
            URI expectedUri = ArchiveFileUtils.toTarUri(file.toURI(), entry.getName());
            IdentificationRequest mockRequest = mock(IdentificationRequest.class);
            when(mockRequest.toString()).thenReturn(expectedUri.toString());
           
            RequestIdentifier expectedIdentifier = new RequestIdentifier(expectedUri);
View Full Code Here

    @Before
    public void setup() throws Exception {
       
        fileName = getClass().getResource("/saved.tar").getFile();
       
        in = new TarArchiveInputStream(new FileInputStream(fileName));
        TarArchiveEntry entry;
        while ((entry = in.getNextTarEntry()) != null) {
            entryName = entry.getName();
            if ("saved/profile.xml".equals(entryName)) {
                size = entry.getSize();
View Full Code Here

    TarArchiveOutputStream newArchiveOut =
        new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(newArchive)));
    newArchiveOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);

    TarArchiveInputStream archiveIn = new TarArchiveInputStream(new GZIPInputStream(in));
    String pathToReplace = null;
    try {
      // copy the existing entries
      for (ArchiveEntry nextEntry = null; (nextEntry = archiveIn.getNextEntry()) != null;) {
        if (nextEntry.getName().endsWith(name)) {
          pathToReplace = nextEntry.getName();
        }
        newArchiveOut.putArchiveEntry(nextEntry);
        IOUtils.copy(archiveIn, newArchiveOut);
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.tar.TarArchiveInputStream

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.