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

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


        }
       
        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

  public void extract( @Nonnull File destination, @Nonnull final InputStream inputStream ) throws IOException {
    if ( !destination.exists() || !destination.isDirectory() ) {
      throw new IllegalArgumentException( "Invalid destination: " + destination.getCanonicalPath() );
    }

    ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream( inputStream );
    try {

      byte[] buf = new byte[BUFFER_LENGTH];
      for ( ArchiveEntry zipEntry = zipInputStream.getNextEntry(); zipEntry != null; zipEntry = zipInputStream.getNextEntry() ) {
        if ( condition != null && !condition.shallExtract( zipEntry ) ) {
          continue;
        }

        String entryName = zipEntry.getName();
        File newFile = new File( destination, entryName );

        //Is a directory
        if ( zipEntry.isDirectory() ) {
          newFile.mkdirs();
          continue;
        }

        //Make the directory structure
        newFile.getParentFile().mkdirs();

        FileOutputStream fileoutputstream = new FileOutputStream( newFile );
        try {
          int n;
          while ( ( n = zipInputStream.read( buf, 0, BUFFER_LENGTH ) ) > -1 ) {
            fileoutputstream.write( buf, 0, n );
          }
        } finally {
          fileoutputstream.close();
        }
      }
    } finally {
      zipInputStream.close();
    }
  }
View Full Code Here

     * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-93"
     *        >COMPRESS-93</a>
     */
    public void testSkipEntryWithUnsupportedCompressionMethod()
            throws IOException {
        ZipArchiveInputStream zip =
            new ZipArchiveInputStream(new FileInputStream(getFile("moby.zip")));
        try {
            ZipArchiveEntry entry = zip.getNextZipEntry();
            assertEquals("README", entry.getName());
            assertFalse(zip.canReadEntryData(entry));
            try {
                assertNull(zip.getNextZipEntry());
            } catch (IOException e) {
                fail("COMPRESS-93: Unable to skip an unsupported zip entry");
            }
        } finally {
            zip.close();
        }
    }
View Full Code Here

        final String newPath = "zip:" + slash1 + path + request.getFileName() + "!" + slash;
        slash1 = "";
        InputStream zipIn = null;
        try {
            zipIn = request.getSourceInputStream();
            final ZipArchiveInputStream in = new ZipArchiveInputStream(zipIn);
            try {
                ZipArchiveEntry entry = null;
                while ((entry = (ZipArchiveEntry) in.getNextZipEntry()) != null) {
                    final String name = entry.getName();
                    if (!entry.isDirectory()) {
                        final RequestMetaData metaData = new RequestMetaData(1L, 2L, name);
                        final RequestIdentifier identifier = new RequestIdentifier(uri);
                        final ZipEntryIdentificationRequest zipRequest =
                            new ZipEntryIdentificationRequest(metaData, identifier, tmpDir);
                       
                        zipRequest.open(in);
                        final IdentificationResultCollection zipResults =
                                binarySignatureIdentifier.matchBinarySignatures(zipRequest);
                        final ResultPrinter resultPrinter =
                                new ResultPrinter(binarySignatureIdentifier,
                                    containerSignatureDefinitions, newPath, slash, slash1, true);
                        resultPrinter.print(zipResults, zipRequest);
                    }
                }
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        } catch (IOException ioe) {
            System.err.println(ioe + " (" + newPath + ")"); // continue after corrupt archive
        } finally {
View Full Code Here

            throw new LDPathException(msg, e);
        }

        try {
            InputStream is = getSolrTemplateStream();
            ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
            ZipArchiveEntry ze = null;
            byte[] schemaFile = null;
            while ((ze = zis.getNextZipEntry()) != null) {
                if (SOLR_TEMPLATE_SCHEMA.equals(ze.getName())) {
                    schemaFile = createSchemaXML(getLDPathProgram(ldPathProgram), IOUtils.toByteArray(zis));
                    TarArchiveEntry te = new TarArchiveEntry(coreName + SOLR_SCHEMA);
                    te.setSize(schemaFile.length);
                    tarOutputStream.putArchiveEntry(te);
View Full Code Here

TOP

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

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.