Package java.util.zip

Examples of java.util.zip.ZipInputStream


    }
  }
 
  private Map<String, WarItem> readWar(byte[] data) throws IOException {
    ByteArrayInputStream inputData = new ByteArrayInputStream(data);
    ZipInputStream in = new ZipInputStream(inputData);
    Map<String, WarItem> map = new HashMap<String, WarItem>();
    ZipEntry entry;
    byte[] buffer = new byte[4096];
    while((entry = in.getNextEntry()) != null) {
      if (!entry.isDirectory()) {
        ByteArrayOutputStream itemData = new ByteArrayOutputStream();
        int len = 0;
        while ((len = in.read(buffer)) > 0) {
          itemData.write(buffer, 0, len);
        }
        WarItem item = new WarItem(entry.getName(), itemData);
        map.put(entry.getName(), item);
      }
    }
    in.close();
    return map;
  }
View Full Code Here


      // Add to pluginPackages all the packages contained in the plugin URLs
      String [] urlStrings = pluginURLs.split("\\s|,");
      for (int i = 0; i < urlStrings.length; i++) {
        try {
          URL pluginUrl = new URL(getCodeBase(), urlStrings [i]);
          ZipInputStream zipIn = null;
          try {
            // Open a zip input from pluginUrl
            zipIn = new ZipInputStream(pluginUrl.openStream());
            // Try directories in current zip stream 
            for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
              String zipEntryName = entry.getName();
              int lastIndex = zipEntryName.lastIndexOf('/');
              if (zipEntryName.endsWith(".class")) {
                if (lastIndex == -1) {
                  pluginPackages.add(""); // Add empty package
                } else {
                  pluginPackages.add(zipEntryName.substring(0, lastIndex).replace('/', '.'));
                }
              }
            }
          } catch (IOException ex) {
            // Ignore furniture plugin
          } finally {
            if (zipIn != null) {
              try {
                zipIn.close();
              } catch (IOException ex) {
              }
            }
          }
        } catch (MalformedURLException ex) {
View Full Code Here

        } finally {
            mimeOutStream.close();
        }
        log.debug("Extracted mime types file");

        final ZipInputStream zipStream = new ZipInputStream(zipFileStream);
        try {
            while ((entry = zipStream.getNextEntry()) != null) {
                newNode = new File(dataDir, entry.getName());
                if (entry.isDirectory()) {
                    if (!newNode.mkdir())
                        throw new IOException("Failed to extract dir '"
                                + entry.getName() + "' from 'data.zip' file");
                    log.debug("Extracted dir '" + entry.getName() + "' to '"
                            + newNode.getAbsolutePath() + "'");
                    zipStream.closeEntry();
                    continue;
                }
                fileSize = entry.getSize();
                fileStream = new FileOutputStream(newNode);
                try {
                    bytesRead = 0;
                    while ((i = zipStream.read(buffer)) > 0) {
                        fileStream.write(buffer, 0, i);
                        bytesRead += i;
                    }
                    fileStream.flush();
                } finally {
                    fileStream.close();
                }
                zipStream.closeEntry();
                if (bytesRead != fileSize)
                    throw new IOException("Expected " + fileSize
                            + " bytes for '" + entry.getName()
                            + ", but extracted " + bytesRead + " bytes to '"
                            + newNode.getAbsolutePath() + "'");
                log.debug("Extracted file '" + entry.getName() + "' to '"
                        + newNode.getAbsolutePath() + "'");
            }
        } finally {
            zipStream.close();
        }
    }
View Full Code Here

            }
            final String fileUrl = ctx.getResource(filePath).toExternalForm();
            try {
                final String jarItemPath = tldPath.jarItemPath;
                if(jarItemPath != null) {
                    final ZipInputStream zin = new ZipInputStream(in);
                    for(;;) {
                        final ZipEntry ze = zin.getNextEntry();
                        if(ze == null) {
                            throw new TemplateModelException(
                                "Could not find JAR entry " + jarItemPath +
                                " inside webapp resource " + filePath +
                                " for URI " + uri);
View Full Code Here

  /**
   * Returns the languages included in the given language library file.
   */
  private Set<String> getLanguages(File languageLibraryFile) throws IOException {
    Set<String> languages = new LinkedHashSet<String>();
    ZipInputStream zipIn = null;
    try {
      // Search if zip file contains some *_xx.properties or *_xx_xx.properties files
      zipIn = new ZipInputStream(new FileInputStream(languageLibraryFile));
      for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
        String zipEntryName = entry.getName();
        int underscoreIndex = zipEntryName.indexOf('_');
        if (underscoreIndex != -1) {
          int extensionIndex = zipEntryName.lastIndexOf(".properties");
          if (extensionIndex != -1 && underscoreIndex < extensionIndex - 2) {
            String language = zipEntryName.substring(underscoreIndex + 1, extensionIndex);
            int countrySeparator = language.indexOf('_');
            if (countrySeparator == 2
                && language.length() == 5) {
              languages.add(language);
            } else if (language.length() == 2) {
              languages.add(language);
            }
          }
        }
      }
      return languages;
    } finally {
      if (zipIn != null) {
        zipIn.close();
      }
    }
  }
View Full Code Here

         
          f.mkdir();
         
          log.debug("##### WRITE FILE TO: " + completeName);
         
          ZipInputStream zipinputstream = new ZipInputStream(is);
          byte[] buf = new byte[1024];
         
          ZipEntry zipentry = zipinputstream.getNextEntry();
         
          while (zipentry != null) {
                  //for each entry to be extracted
                  String entryName = completeName + File.separatorChar + zipentry.getName();
                  entryName = entryName.replace('/', File.separatorChar);
                  entryName = entryName.replace('\\', File.separatorChar);
                 
                  //log.debug("entryname " + entryName);
                 
                  //zipentry.get
                 
                  int n;
                  FileOutputStream fileoutputstream;
                  File newFile = new File(entryName);
                 
                 
                  if (zipentry.isDirectory()) {
                      if (!newFile.mkdir()) {
                          break;
                      }
                      zipentry = zipinputstream.getNextEntry();
                      continue;
                  }
                 
                  File fentryName = new File(entryName);
                 
                  File fparent = new File(fentryName.getParent());
                 
                  if (!fparent.exists()) {
                   
                    File fparentparent = new File(fparent.getParent());
                   
                    if (!fparentparent.exists()) {
                     
                      File fparentparentparent = new File(fparentparent.getParent());
                     
                      if (!fparentparentparent.exists()) {
                       
                        fparentparentparent.mkdir();
                        fparentparent.mkdir();
                        fparent.mkdir();
                       
                      } else {
                       
                        fparentparent.mkdir();
                        fparent.mkdir();
                       
                      }
                     
                    } else {
                     
                      fparent.mkdir();
                     
                    }
                   
                  }
                 

                  fileoutputstream = new FileOutputStream(entryName);

                  while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
                      fileoutputstream.write(buf, 0, n);
                  }

                  fileoutputstream.close();
                  zipinputstream.closeEntry();
                  zipentry = zipinputstream.getNextEntry();

              }//while

                zipinputstream.close();
               
         
          /* #####################
           * Import Organizations
           */
 
View Full Code Here

      xcutSet.addOrReplaceAspect(addedAspect);
    }
  }

  private List<ResolvedType> addAspectsFromJarFile(File inFile) throws FileNotFoundException, IOException {
    ZipInputStream inStream = new ZipInputStream(new FileInputStream(inFile)); // ??? buffered
    List<ResolvedType> addedAspects = new ArrayList<ResolvedType>();
    try {
      while (true) {
        ZipEntry entry = inStream.getNextEntry();
        if (entry == null) {
          break;
        }

        if (entry.isDirectory() || !entry.getName().endsWith(".class")) {
          continue;
        }

        // FIXME ASC performance? of this alternative soln.
        int size = (int) entry.getSize();
        ClassParser parser = new ClassParser(new ByteArrayInputStream(FileUtil.readAsByteArray(inStream)), entry.getName());
        JavaClass jc = parser.parse();
        inStream.closeEntry();

        ResolvedType type = world.addSourceObjectType(jc, false).getResolvedTypeX();
        type.setBinaryPath(inFile.getAbsolutePath());
        if (type.isAspect()) {
          addedAspects.add(type);
        }

      }
    } finally {
      inStream.close();
    }
    return addedAspects;
  }
View Full Code Here

    output.putNextEntry(new ZipEntry(entryName));
    return output;
  }

  @Override public InputStream getDecoderStream(InputStream source) throws IOException {
    ZipInputStream zipped = new ZipInputStream(source);
    zipped.getNextEntry();
    return zipped;
  }
View Full Code Here

        }
        return true;
    }

    public static void deflate(File archive, String entryName, File to, boolean deleteCopy) throws IOException {
        ZipInputStream zis = null;
        InputStream is = null;

        byte[] buffer = new byte[16 * 1024];

        ZipFile zipFile = null;
        try {
            is = new BufferedInputStream(new FileInputStream(archive));
            zipFile = new ZipFile(archive);
            zis = new ZipInputStream(is);
            while (true) {
                ZipEntry entry = zis.getNextEntry();
                if (entry == null) {
                    break;
                }
                if (entry.isDirectory() || !entryName.equals(entry.getName())) {
                    zis.closeEntry();
                    continue;
                }
                InputStream fis = null;
                OutputStream fos = null;
                try {
                    fis = new BufferedInputStream(zipFile.getInputStream(entry));
                    fos = new BufferedOutputStream(new FileOutputStream(to));
                    while (true) {
                        int r = fis.read(buffer);
                        if (r < 0) {
                            break;
                        } else if (r == 0) {
                            continue;
                        }
                        fos.write(buffer, 0, r);
                    }
                } finally {
                    if (fos != null) {
                        try {
                            fos.close();
                        } catch (IOException e) {
                        }
                    }
                    if (fis != null) {
                        try {
                            fis.close();
                        } catch (IOException e) {
                        }
                    }
                }
                if (deleteCopy) {
                    to.deleteOnExit();
                }
                zis.closeEntry();
                break;
            }
        } finally {
            if (zis != null) {
                try {
                    zis.close();
                } catch (IOException e) {
                }
            }
            if (is != null) {
                try {
View Full Code Here

   * @param entryName The name of the entry to get the data for
   * @return The binary data for the entry, or null if it does not exist or could not be found
   */
  public static byte[] getZipEntryData (InputStream input, String entryName) throws IOException {
    try {
      ZipInputStream zis = new ZipInputStream(input);
      ZipEntry entry = null;
      byte[] buffer = new byte[10956];
      while ( (entry = zis.getNextEntry()) != null ) {
        if (entry.getName().equals(entryName)) {
          return IOUtil.read(zis, buffer, false);
        }
      }
      return null;
View Full Code Here

TOP

Related Classes of java.util.zip.ZipInputStream

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.