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

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


        zos.setEncoding(encoding);
      }
      for (int i = 0; i < fileNames.size(); i++) {
        String fileName = fileNames.get(i);
        String entryName = StringUtils.substringAfterLast(fileName, File.separator);
        ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
        zos.putArchiveEntry(entry);
        FileInputStream fis = new FileInputStream(fileName);
        IOUtils.copy(fis, zos);
        fis.close();
        zos.closeArchiveEntry();
View Full Code Here


      file = null;
      if (null == encoding) file = new ZipFile(zipFile);
      else file = new ZipFile(zipFile, encoding);
      @SuppressWarnings("unchecked")
      Enumeration<ZipArchiveEntry> en = file.getEntries();
      ZipArchiveEntry ze = null;
      while (en.hasMoreElements()) {
        ze = en.nextElement();
        File f = new File(dest, ze.getName());
        if (ze.isDirectory()) {
          f.mkdirs();
          continue;
        } else {
          f.getParentFile().mkdirs();
          InputStream is = file.getInputStream(ze);
View Full Code Here

    ZipArchiveOutputStream newZipStream = new ZipArchiveOutputStream(zipFile);
    //add this uncompressed file to the archive
    int bytesRead;
    byte[] buffer = new byte[1024 * 1024];

    ZipArchiveEntry zipEntry = new ZipArchiveEntry(fileToZip.getName());
    newZipStream.putArchiveEntry(zipEntry);
    FileInputStream currentFileStream = new FileInputStream(fileToZip);
    while ((bytesRead = currentFileStream.read(buffer))!= -1) {
      newZipStream.write(buffer, 0, bytesRead);
    }
View Full Code Here

            logger.debug("Adding uncompressed file...");
            //add this uncompressed file to the archive
            int bytesRead;
            String entryName = currentFile.getName();
            logger.debug("Zipping: " + entryName);
            ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName);
            newZipStream.putArchiveEntry(zipEntry);
            while ((bytesRead = currentFileStream.read(buffer))!= -1) {
              newZipStream.write(buffer, 0, bytesRead);
            }
            newZipStream.closeArchiveEntry();
          } else {
            logger.debug("Adding entries from compressed file...");
            //read the entries from the zip file and copy them to the new zip archive
            //so that we don't have to recompress them.
            ZipArchiveInputStream currentZipStream = new ZipArchiveInputStream(currentFileStream);
            ArchiveEntry currentEntry;
            while ((currentEntry = currentZipStream.getNextEntry()) != null) {
              String entryName = currentEntry.getName();
              logger.debug("Zipping: " + entryName);
              ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName);
              try {
                newZipStream.putArchiveEntry(zipEntry);
              } catch (Exception e){
                //duplicate names should never happen.
                entryName = Math.round(Math.random() * 10000) + "_" + entryName;
                ZipArchiveEntry zipEntry2 = new ZipArchiveEntry(entryName);
                newZipStream.putArchiveEntry(zipEntry2);
              }
              int bytesRead;
              while ((bytesRead = currentZipStream.read(buffer))!= -1) {
                newZipStream.write(buffer, 0, bytesRead);
View Full Code Here

        }
        ZipFile zipFile = new ZipFile(zipArchive);
      Enumeration<ZipArchiveEntry> entries = zipFile.getEntriesInPhysicalOrder();
     
      while (entries.hasMoreElements()) {
        ZipArchiveEntry currentEntry = entries.nextElement();
        String entryName = currentEntry.getName();
        logger.debug("Current entry: " + entryName);
        try {
          logger.debug(zipArchive.getParent() + "/" + currentEntry.getName());
          File destFile = new File(containerDir, currentEntry.getName());
          if (currentEntry.isDirectory()){
            destFile.mkdir();
            logger.debug("created directory: " + destFile.getAbsolutePath());
            // create the parent directory structure if needed
          } else {
            File parentDir = destFile.getParentFile();
View Full Code Here

        ArchiveOutputStream os = null;
        try {
            try {
                out_zip = new FileOutputStream(to);
                os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out_zip);
                os.putArchiveEntry(new ZipArchiveEntry(from.getName()));
                IOUtils.copy(new FileInputStream(from), os);
                os.closeArchiveEntry();
            } finally {
                if (os != null) {
                    os.close();
View Full Code Here

                                                       String entry)
      throws IOException {
    InputStream is = null;
    FSDataInputStream appStream = fs.open(appPath);
    ZipArchiveInputStream zis = new ZipArchiveInputStream(appStream);
    ZipArchiveEntry zipEntry;
    boolean done = false;
    while (!done && (zipEntry = zis.getNextZipEntry()) != null) {
      if (entry.equals(zipEntry.getName())) {
        int size = (int) zipEntry.getSize();
        byte[] content = new byte[size];
        int offset = 0;
        while (offset < size) {
          offset += zis.read(content, offset, size - offset);
        }
View Full Code Here

     *  entry in the root of their Zip file. This entry contains the
     *  mimetype of the overall file, stored as a single string. 
     */
    private static MediaType detectOpenDocument(ZipFile zip) {
        try {
            ZipArchiveEntry mimetype = zip.getEntry("mimetype");
            if (mimetype != null) {
                InputStream stream = zip.getInputStream(mimetype);
                try {
                    return MediaType.parse(IOUtils.toString(stream, "UTF-8"));
                } finally {
View Full Code Here

    private static MediaType detectKmz(ZipFile zip) {
        boolean kmlFound = false;

        Enumeration<ZipArchiveEntry> entries = zip.getEntries();
        while (entries.hasMoreElements()) {
            ZipArchiveEntry entry = entries.nextElement();
            String name = entry.getName();
            if (!entry.isDirectory()
                    && name.indexOf('/') == -1 && name.indexOf('\\') == -1) {
                if (name.endsWith(".kml") && !kmlFound) {
                    kmlFound = true;
                } else {
                    return null;
View Full Code Here

        // Note - consider generalising this logic, if another format needs many regexp matching
        Set<Pattern> tmpPatterns = (Set<Pattern>)ipaEntryPatterns.clone();
       
        Enumeration<ZipArchiveEntry> entries = zip.getEntries();
        while (entries.hasMoreElements()) {
            ZipArchiveEntry entry = entries.nextElement();
            String name = entry.getName();
           
            Iterator<Pattern> ip = tmpPatterns.iterator();
            while (ip.hasNext()) {
                if (ip.next().matcher(name).matches()) {
                    ip.remove();
View Full Code Here

TOP

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

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.