Package java.util.zip

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


      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

  /**
   * 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

          + " " + 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

      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

      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

    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

    }

    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

            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

      extractZipFile(basedir, in, true);
  }

  public static final void extractZipFile(File basedir, InputStream in, boolean onlyIfNewer) throws IOException {

    ZipInputStream zin = new ZipInputStream(in);
    try {
     

      ZipEntry entry;
      byte[] buf = new byte[32768];
      int read;
      do {
         entry = zin.getNextEntry();
        
         if(entry==null)
           break;
        
         File f =  new File(basedir, entry.getName());
        
         if(entry.isDirectory()) {
             f.mkdirs();
             zin.closeEntry();
             if(entry.getTime() != -1) {
                 f.setLastModified(entry.getTime());
             }
             continue;
         }
        
         if(onlyIfNewer && entry.getTime() != -1 && entry.getTime() == f.lastModified()) {
             continue;
         }
        
         f.getParentFile().mkdirs();
         FileOutputStream out = new FileOutputStream(f);
        
         try {
           while((read = zin.read(buf, 0, buf.length)) > -1) {
             out.write(buf, 0, read);
           }
          
           zin.closeEntry();
        
         } finally {
           Util.closeStream(out);
         }
         if(entry.getTime() != -1) {
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.