Package org.apache.commons.compress.archivers.zip

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream


    Response response = WebClient.create(endPoint + ALL_PATH)
        .header(CONTENT_TYPE, APPLICATION_XML)
        .accept("application/zip")
        .put(ClassLoader.getSystemResourceAsStream("test.doc"));

    String responseMsg = readArchiveText(new ZipArchiveInputStream(
        (InputStream) response.getEntity()));
    assertNotNull(responseMsg);
    assertTrue(responseMsg.contains("test"));
  }
View Full Code Here


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

        in.mark(signature.length);
        try {
            int signatureLength = in.read(signature);
            in.reset();
            if (ZipArchiveInputStream.matches(signature, signatureLength)) {
                return new ZipArchiveInputStream(in);
            } else if (JarArchiveInputStream.matches(signature, signatureLength)) {
                return new JarArchiveInputStream(in);
            } else if (ArArchiveInputStream.matches(signature, signatureLength)) {
                return new ArArchiveInputStream(in);
            } else if (CpioArchiveInputStream.matches(signature, signatureLength)) {
View Full Code Here

        extract(new TarArchiveInputStream(new FileInputStream(uncompressedFile)), targetFolder);
        FileUtils.forceDelete(uncompressedFile);
    }

    private void extractZipDistribution(URL sourceDistribution, File targetFolder) throws IOException {
        extract(new ZipArchiveInputStream(sourceDistribution.openStream()), targetFolder);
    }
View Full Code Here

        }
       
        List<URI> expectedDirectories = new ArrayList<URI>();
        IdentificationRequestFactory factory = mock(IdentificationRequestFactory.class);
       
        ZipArchiveInputStream zin = new ZipArchiveInputStream(new FileInputStream(file));
        int entryCount = 0;
        ZipArchiveEntry entry;
        ResourceId parentId = new ResourceId(20L, "X");
        ResourceId nodeId = new ResourceId(20L, "X");
        while ((entry = zin.getNextZipEntry()) != null) {
            URI expectedUri = ArchiveFileUtils.toZipUri(file.toURI(), entry.getName());
           
            RequestIdentifier identifer = new RequestIdentifier(expectedUri);
            identifer.setAncestorId(10L);
            identifer.setParentResourceId(parentId);
View Full Code Here

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

        InputStream in = request.getSourceInputStream();
        try {
            final ZipArchiveInputStream zin = new ZipArchiveInputStream(in);
           
            try {
                Iterable<ZipArchiveEntry> iterable = new Iterable<ZipArchiveEntry>() {
                    @Override
                    public final Iterator<ZipArchiveEntry> iterator() {
                        return new ZipInputStreamIterator(zin);
                    }
                };
                
       
                ZipArchiveWalker walker = new ZipArchiveWalker(zin, request.getIdentifier())
                walker.walk(iterable);
            } finally {
                if (zin != null) {
                    zin.close();
                }
            }
        } finally {
            if (in != null) {
                in.close();
View Full Code Here

  }

  public void unzip() throws IOException {
    SimpleLogger.debug("Unzipping archive " + archiveFile + " ...");

    ZipArchiveInputStream zipStream     = null;
    ZipEntry              zipEntry;
    byte[]                buffer        = new byte[BUFFER_SIZE];
    int                   byteCount;
    File                  unzippedFile;
    BufferedOutputStream  outUnzipped   = null;

    try {
      zipStream = new ZipArchiveInputStream(
        new BufferedInputStream(new FileInputStream(archiveFile), BUFFER_SIZE),
        "Cp437", false
      );
      while ((zipEntry = zipStream.getNextZipEntry()) != null) {
        SimpleLogger.debug("  Extracting " + zipEntry);
        unzippedFile = new File(targetDirectory, zipEntry.getName());
        if (zipEntry.isDirectory()) {
          if (! unzippedFile.exists() && ! unzippedFile.mkdirs())
            throw new IOException("Cannot create directory '" + unzippedFile + "'");
          continue;
        }
        File parentDir = unzippedFile.getParentFile();
        if (! parentDir.exists() && ! parentDir.mkdirs())
          throw new IOException("Cannot create directory '" + parentDir + "'");
        outUnzipped = new BufferedOutputStream(new FileOutputStream(unzippedFile), BUFFER_SIZE);
        while ((byteCount = zipStream.read(buffer, 0, BUFFER_SIZE)) != -1)
          outUnzipped.write(buffer, 0, byteCount);
        outUnzipped.close();
      }
    }
    finally {
      try {
        if (outUnzipped != null)
          outUnzipped.close();
      } catch (IOException ignored) {}
      try {
        if (zipStream != null)
          zipStream.close();
      } catch (IOException ignored) {}
    }
    SimpleLogger.debug("Unzipping done");
  }
View Full Code Here

                        .getEntry("/data-files/" + indexArchiveName + ".solrindex.zip");
                if (archiveUrl == null) {
                    throw new ConfigurationException(solrCoreId, "Could not find index archive for "
                                                                 + indexArchiveName);
                }
                ZipArchiveInputStream zis = new ZipArchiveInputStream(archiveUrl.openStream());
                indexMetadata = managedSolrServer.updateIndex(indexName, zis, indexArchiveName);
            }
            if (!indexMetadata.isActive()) {
                managedSolrServer.activateIndex(indexName);
            }
View Full Code Here

    deleteTemporaryComponentOutputDirectory(buildDirectory);

    /*
     * Create archive input stream
     */
    ZipArchiveInputStream existingInputStream = new ZipArchiveInputStream(new FileInputStream(existingArchiveFile));

    /*
     * Create a zip archive output stream for the temp file
     */
    ZipArchiveOutputStream tempOutputStream = new ZipArchiveOutputStream(tempArchiveFile);

    /*
     * Iterate through all existing entries adding them to the new archive
     */
    ZipArchiveEntry curArchiveEntry;

    Set<String> existingArchiveEntryNames = new HashSet<String>();

    while ((curArchiveEntry = existingInputStream.getNextZipEntry()) != null) {
      existingArchiveEntryNames.add(curArchiveEntry.getName().toLowerCase());
      getLog().debug("Current File Name: " + curArchiveEntry.getName());
      tempOutputStream.putArchiveEntry(curArchiveEntry);
      IOUtils.copy(existingInputStream, tempOutputStream);
      tempOutputStream.closeArchiveEntry();
    }

    /*
     * Create content.xml within temp archive
     */
    ContentUtil.buildContentFromClassList(classList, tempOutputStream, existingArchiveEntryNames, buildDirectory,
      componentPathBase, defaultComponentPathSuffix, defaultComponentGroup, transformer);

    /*
     * Create Dialogs within temp archive
     */
    DialogUtil.buildDialogsFromClassList(transformer, classList, tempOutputStream, existingArchiveEntryNames,
      widgetRegistry, classLoader, classPool, buildDirectory, componentPathBase, defaultComponentPathSuffix);

    /*
     * Create edit config within temp archive
     */
    EditConfigUtil.buildEditConfigFromClassList(classList, tempOutputStream, existingArchiveEntryNames,
      buildDirectory, componentPathBase, defaultComponentPathSuffix, transformer);

    /*
     * Copy temp archive to the original archive position
     */
    tempOutputStream.finish();
    existingInputStream.close();
    tempOutputStream.close();

    existingArchiveFile.delete();
    tempArchiveFile.renameTo(existingArchiveFile);

 
View Full Code Here

    deleteTemporaryComponentOutputDirectory(buildDirectory);

    /*
     * Create archive input stream
     */
    ZipArchiveInputStream existingInputStream = new ZipArchiveInputStream(new FileInputStream(existingArchiveFile));

    /*
     * Create a zip archive output stream for the temp file
     */
    ZipArchiveOutputStream tempOutputStream = new ZipArchiveOutputStream(tempArchiveFile);

    /*
     * Iterate through all existing entries adding them to the new archive
     */
    ZipArchiveEntry curArchiveEntry;

    Set<String> existingArchiveEntryNames = new HashSet<String>();

    while ((curArchiveEntry = existingInputStream.getNextZipEntry()) != null) {
      existingArchiveEntryNames.add(curArchiveEntry.getName().toLowerCase());
      getLog().debug("Current File Name: " + curArchiveEntry.getName());
      tempOutputStream.putArchiveEntry(curArchiveEntry);
      IOUtils.copy(existingInputStream, tempOutputStream);
      tempOutputStream.closeArchiveEntry();
    }

    /*
     * Create content.xml within temp archive
     */
    ContentUtil.buildContentFromClassList(classList, tempOutputStream, existingArchiveEntryNames, buildDirectory,
      componentPathBase, defaultComponentPathSuffix, defaultComponentGroup, transformer);

    /*
     * Create Dialogs within temp archive
     */
    DialogUtil.buildDialogsFromClassList(transformer, classList, tempOutputStream, existingArchiveEntryNames,
      widgetRegistry, classLoader, classPool, buildDirectory, componentPathBase, defaultComponentPathSuffix);

    /*
     * Create edit config within temp archive
     */
    EditConfigUtil.buildEditConfigFromClassList(classList, tempOutputStream, existingArchiveEntryNames,
      buildDirectory, componentPathBase, defaultComponentPathSuffix, transformer);

    /*
     * Copy temp archive to the original archive position
     */
    tempOutputStream.finish();
    existingInputStream.close();
    tempOutputStream.close();

    existingArchiveFile.delete();
    tempArchiveFile.renameTo(existingArchiveFile);

 
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

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.