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

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


        if (AR.equalsIgnoreCase(archiverName)) {
            return new ArArchiveOutputStream(out);
        }
        if (ZIP.equalsIgnoreCase(archiverName)) {
            return new ZipArchiveOutputStream(out);
        }
        if (TAR.equalsIgnoreCase(archiverName)) {
            return new TarArchiveOutputStream(out);
        }
        if (JAR.equalsIgnoreCase(archiverName)) {
View Full Code Here


    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

    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 testDirectoryEntryFromFile() throws Exception {
        File[] tmp = createTempDirAndFile();
        File archive = null;
        ZipArchiveOutputStream zos = null;
        ZipFile zf = null;
        try {
            archive = File.createTempFile("test.", ".zip", tmp[0]);
            archive.deleteOnExit();
            zos = new ZipArchiveOutputStream(archive);
            long beforeArchiveWrite = tmp[0].lastModified();
            ZipArchiveEntry in = new ZipArchiveEntry(tmp[0], "foo");
            zos.putArchiveEntry(in);
            zos.closeArchiveEntry();
            zos.close();
            zos = null;
            zf = new ZipFile(archive);
            ZipArchiveEntry out = zf.getEntry("foo/");
            assertNotNull(out);
            assertEquals("foo/", out.getName());
            assertEquals(0, out.getSize());
            // ZIP stores time with a granularity of 2 seconds
            assertEquals(beforeArchiveWrite / 2000,
                         out.getLastModifiedDate().getTime() / 2000);
            assertTrue(out.isDirectory());
        } finally {
            ZipFile.closeQuietly(zf);
            if (zos != null) {
                zos.close();
            }
            tryHardToDelete(archive);
            tryHardToDelete(tmp[1]);
            rmdir(tmp[0]);
        }
View Full Code Here

    }

    public void testExplicitDirectoryEntry() throws Exception {
        File[] tmp = createTempDirAndFile();
        File archive = null;
        ZipArchiveOutputStream zos = null;
        ZipFile zf = null;
        try {
            archive = File.createTempFile("test.", ".zip", tmp[0]);
            archive.deleteOnExit();
            zos = new ZipArchiveOutputStream(archive);
            long beforeArchiveWrite = tmp[0].lastModified();
            ZipArchiveEntry in = new ZipArchiveEntry("foo/");
            in.setTime(beforeArchiveWrite);
            zos.putArchiveEntry(in);
            zos.closeArchiveEntry();
            zos.close();
            zos = null;
            zf = new ZipFile(archive);
            ZipArchiveEntry out = zf.getEntry("foo/");
            assertNotNull(out);
            assertEquals("foo/", out.getName());
            assertEquals(0, out.getSize());
            assertEquals(beforeArchiveWrite / 2000,
                         out.getLastModifiedDate().getTime() / 2000);
            assertTrue(out.isDirectory());
        } finally {
            ZipFile.closeQuietly(zf);
            if (zos != null) {
                zos.close();
            }
            tryHardToDelete(archive);
            tryHardToDelete(tmp[1]);
            rmdir(tmp[0]);
        }
View Full Code Here

    }

    public void testFileEntryFromFile() throws Exception {
        File[] tmp = createTempDirAndFile();
        File archive = null;
        ZipArchiveOutputStream zos = null;
        ZipFile zf = null;
        FileInputStream fis = null;
        try {
            archive = File.createTempFile("test.", ".zip", tmp[0]);
            archive.deleteOnExit();
            zos = new ZipArchiveOutputStream(archive);
            ZipArchiveEntry in = new ZipArchiveEntry(tmp[1], "foo");
            zos.putArchiveEntry(in);
            byte[] b = new byte[(int) tmp[1].length()];
            fis = new FileInputStream(tmp[1]);
            while (fis.read(b) > 0) {
                zos.write(b);
            }
            fis.close();
            fis = null;
            zos.closeArchiveEntry();
            zos.close();
            zos = null;
            zf = new ZipFile(archive);
            ZipArchiveEntry out = zf.getEntry("foo");
            assertNotNull(out);
            assertEquals("foo", out.getName());
            assertEquals(tmp[1].length(), out.getSize());
            assertEquals(tmp[1].lastModified() / 2000,
                         out.getLastModifiedDate().getTime() / 2000);
            assertFalse(out.isDirectory());
        } finally {
            ZipFile.closeQuietly(zf);
            if (zos != null) {
                zos.close();
            }
            tryHardToDelete(archive);
            if (fis != null) {
                fis.close();
            }
View Full Code Here

    }

    public void testExplicitFileEntry() throws Exception {
        File[] tmp = createTempDirAndFile();
        File archive = null;
        ZipArchiveOutputStream zos = null;
        ZipFile zf = null;
        FileInputStream fis = null;
        try {
            archive = File.createTempFile("test.", ".zip", tmp[0]);
            archive.deleteOnExit();
            zos = new ZipArchiveOutputStream(archive);
            ZipArchiveEntry in = new ZipArchiveEntry("foo");
            in.setTime(tmp[1].lastModified());
            in.setSize(tmp[1].length());
            zos.putArchiveEntry(in);
            byte[] b = new byte[(int) tmp[1].length()];
            fis = new FileInputStream(tmp[1]);
            while (fis.read(b) > 0) {
                zos.write(b);
            }
            fis.close();
            fis = null;
            zos.closeArchiveEntry();
            zos.close();
            zos = null;
            zf = new ZipFile(archive);
            ZipArchiveEntry out = zf.getEntry("foo");
            assertNotNull(out);
            assertEquals("foo", out.getName());
            assertEquals(tmp[1].length(), out.getSize());
            assertEquals(tmp[1].lastModified() / 2000,
                         out.getLastModifiedDate().getTime() / 2000);
            assertFalse(out.isDirectory());
        } finally {
            ZipFile.closeQuietly(zf);
            if (zos != null) {
                zos.close();
            }
            tryHardToDelete(archive);
            if (fis != null) {
                fis.close();
            }
View Full Code Here

        if ( !createEmpty )
        {
            return true;
        }

        ZipArchiveOutputStream zOut = null;
        try
        {
            getLogger().debug( "Building MANIFEST-only jar: " + getDestFile().getAbsolutePath() );
            FileOutputStream out = new FileOutputStream( getDestFile() );
            zOut = new ZipArchiveOutputStream( new BufferedOutputStream( out, 65536) );

            zOut.setEncoding( getEncoding() );
            if ( isCompress() )
            {
                zOut.setMethod( ZipArchiveOutputStream.DEFLATED );
            }
            else
            {
                zOut.setMethod( ZipArchiveOutputStream.STORED );
            }
            initZipOutputStream( zOut );
            finalizeZipOutputStream( zOut );
        }
        catch ( IOException ioe )
View Full Code Here

        if ( !skipWriting )
        {
            FileOutputStream out = new FileOutputStream( zipFile );
            BufferedOutputStream buffered = new BufferedOutputStream( out, 65536 );
            zOut = new ZipArchiveOutputStream( buffered );

            zOut.setEncoding( encoding );
            if ( doCompress )
            {
                zOut.setMethod( ZipArchiveOutputStream.DEFLATED );
View Full Code Here

   * @return the zipped file
   *
   * @throws IOException if an io exception occures
   */
  public File zip( @NotNull File... directories ) throws IOException {
    ZipArchiveOutputStream outStream = new ZipArchiveOutputStream( new BufferedOutputStream( new FileOutputStream( zipFile ) ) );
    try {
      for ( File directory : directories ) {
        String baseName = directory.getCanonicalPath();
        addFiles( baseName, outStream, directory );
      }
    } finally {
      outStream.close();
    }
    return zipFile;
  }
View Full Code Here

TOP

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

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.