Examples of ZipInputStream


Examples of java.util.zip.ZipInputStream

  /**
   * Unzips the given file.
   */
  public static File unzip(File file) throws IOException {
    ZipInputStream in = new ZipInputStream(new FileInputStream(file));
    ZipEntry entry = in.getNextEntry();
    String outFilename = entry.getName();
    OutputStream out = new FileOutputStream(outFilename);
    byte[] buf = new byte[4096];
    int len;
    while ((len = in.read(buf)) > 0) {
      out.write(buf, 0, len);
    }
    out.close();
    in.close();
    return new File(outFilename);
  }
View Full Code Here

Examples of java.util.zip.ZipInputStream

      if (tempOut != null) {
        tempOut.close();
      }
    }
   
    ZipInputStream zipIn = null;
    try {
      // Open a zip input from temp file
      zipIn = new ZipInputStream(new FileInputStream(this.tempFile));
      // Read home in first entry
      zipIn.getNextEntry();
      checkCurrentThreadIsntInterrupted();
      // Use an ObjectInputStream that replaces temporary URLs of Content objects
      // by URLs relative to file
      ObjectInputStream objectStream = new HomeObjectInputStream(zipIn);
      return (Home)objectStream.readObject();
    } finally {
      if (zipIn != null) {
        zipIn.close();
      }
    }
  }
View Full Code Here

Examples of java.util.zip.ZipInputStream

  /**
   * Loads the plug-ins that may be available in the given URL.
   */
  private void loadPlugins(URL pluginUrl) {
    ZipInputStream zipIn = null;
    try {
      // Open a zip input from pluginUrl
      zipIn = new ZipInputStream(pluginUrl.openStream());
      // Try do find a plugin properties file in current zip stream 
      for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
        String zipEntryName = entry.getName();
        int lastIndex = zipEntryName.lastIndexOf(DEFAULT_APPLICATION_PLUGIN_PROPERTIES_FILE);
        if (lastIndex != -1
            && (lastIndex == 0
                || zipEntryName.charAt(lastIndex - 1) == '/')) {
          try {
            // Build application plugin family with its package
            String applicationPluginFamily = zipEntryName.substring(0, lastIndex);
            applicationPluginFamily += APPLICATION_PLUGIN_FAMILY;
            ClassLoader classLoader = new URLClassLoader(new URL [] {pluginUrl}, getClass().getClassLoader());
            readPlugin(ResourceBundle.getBundle(applicationPluginFamily, Locale.getDefault(), classLoader),
                "jar:" + pluginUrl.toString() + "!/" + URLEncoder.encode(zipEntryName, "UTF-8").replace("+", "%20"),
                classLoader);
          } catch (MissingResourceException ex) {
            // Ignore malformed plugins
          }
        }
      }
    } catch (IOException ex) {
      // Ignore furniture plugin
    } finally {
      if (zipIn != null) {
        try {
          zipIn.close();
        } catch (IOException ex) {
        }
      }
    }
  }
View Full Code Here

Examples of java.util.zip.ZipInputStream

          + " " + currentFile  + " " + msg.getFileCounter());
      byte[] data = getSystemService().getCache().getBlob(
          msg.getFilename());
      ByteArrayInputStream inputData = new ByteArrayInputStream(data);
      try {
        ZipInputStream in = new ZipInputStream(inputData);
        getImportExportBusiness().importZip(in);
        in.close();
      } catch (IOException e) {
        throw new UploadException(e.getMessage());
      } catch (DocumentException e) {
        throw new UploadException(e.getMessage());
      }
View Full Code Here

Examples of java.util.zip.ZipInputStream

      if (data == null) {
        return;
      }
      ByteArrayInputStream inputData = new ByteArrayInputStream(data);
      try {
        ZipInputStream in = new ZipInputStream(inputData);
        getImportExportBusiness().importZip2(in);
        in.close();
      } catch (IOException e) {
        throw new UploadException(e.getMessage());
      } catch (DocumentException e) {
        throw new UploadException(e.getMessage());
      }
View Full Code Here

Examples of java.util.zip.ZipInputStream

      logger.error("Imported file not found in memcache. "
          + msg.getFilename());
      return;
    }
    ByteArrayInputStream inputData = new ByteArrayInputStream(data);
    ZipInputStream in = new ZipInputStream(inputData);
    try {
      getImportExportBusiness().importUnzip(in, msg.getCurrentFile());
    }
    catch (RequestTimeoutException e) {
      getBusiness().getMessageQueue().publish(new ImportMessage(
          msg.getFilename(), 0, e.getMessage(), 0));
    }
    in.close();
 
View Full Code Here

Examples of java.util.zip.ZipInputStream

    zip.setOutStream(out);
    zip.setOutData(outData);
    if (savedZip != null) {
      ByteArrayInputStream inputData = new ByteArrayInputStream(savedZip);
      try {
        ZipInputStream in = new ZipInputStream(inputData);
        ZipEntry entry;
        while ((entry = in.getNextEntry()) != null) {
          out.putNextEntry(entry);
          if (!entry.isDirectory()) {
                    StreamUtils.readTo(in, out, false, false);
                }
                out.closeEntry();
        }
        in.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
View Full Code Here

Examples of java.util.zip.ZipInputStream

    }

    public static List<String> readXarContents(String fileName, String patternFilter) throws Exception
    {
        FileInputStream fileIS = new FileInputStream(fileName);
        ZipInputStream zipIS = new ZipInputStream(fileIS);

        ZipEntry entry;
        Document tocDoc = null;
        while ((entry = zipIS.getNextEntry()) != null) {
            if (entry.getName().compareTo(Package.DefaultPackageFileName) == 0) {
                SAXReader reader = new SAXReader();
                tocDoc = reader.read(zipIS);
                break;
            }
View Full Code Here

Examples of java.util.zip.ZipInputStream

            File f = new File(Util.urlDecode(url.getPath()));
            if (!f.exists()) {
                return;
            }
            in = new FileInputStream(Util.urlDecode(url.getPath()));
            ZipInputStream zin = new ZipInputStream(in);
            while (true) {
                ZipEntry entry = zin.getNextEntry();
                if (entry == null) {
                    break;
                }
                String path = entry.getName();
                String name = path;
View Full Code Here

Examples of net.sf.jazzlib.ZipInputStream

   * @param versioning enabled or not
   * @return  True if successfull, false otherwise
   */
  public static boolean unzip(VFSLeaf zipLeaf, VFSContainer targetDir, Identity identity, boolean versioning) {

    ZipInputStream oZip = new ZipInputStream(zipLeaf.getInputStream());
   
    try {
      // unzip files
      ZipEntry oEntr = oZip.getNextEntry();
      while (oEntr != null) {
        if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
          if (oEntr.isDirectory()) {
            // skip MacOSX specific metadata directory
            // create directories
            getAllSubdirs(targetDir, oEntr.getName(), true);
          } else {
            // create file
            VFSContainer createIn = targetDir;
            String name = oEntr.getName();
            // check if entry has directories which did not show up as
            // directories above
            int dirSepIndex = name.lastIndexOf('/');
            if (dirSepIndex == -1) {
              // try it windows style, backslash is also valid format
              dirSepIndex = name.lastIndexOf('\\');
            }
            if (dirSepIndex > 0) {
              // create subdirs
              createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), true);
              if (createIn == null) {
                if (log.isDebug()) log.debug("Error creating directory structure for zip entry: "
                    + oEntr.getName());
                return false;
              }
              name = name.substring(dirSepIndex + 1);
            }
           
            if(versioning) {
              VFSLeaf newEntry = (VFSLeaf)createIn.resolve(name);
              if(newEntry == null) {
                newEntry = createIn.createChildLeaf(name);
                OutputStream out = newEntry.getOutputStream(false);
                if (!FileUtils.copy(oZip, out)) return false;
                FileUtils.closeSafely(out);
              } else if (newEntry instanceof Versionable) {
                Versionable versionable = (Versionable)newEntry;
                if(versionable.getVersions().isVersioned()) {
                  versionable.getVersions().addVersion(identity, "", oZip);
                }
              }
            } else {
              VFSLeaf newEntry = createIn.createChildLeaf(name);
              if (newEntry != null) {
                OutputStream out = newEntry.getOutputStream(false);
                if (!FileUtils.copy(oZip, out)) return false;
                FileUtils.closeSafely(out);
              }
            }
          }
        }
        oZip.closeEntry();
        oEntr = oZip.getNextEntry();
      }
    } catch (IOException e) {
      return false;
    } finally {
      FileUtils.closeSafely(oZip);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.