Package java.util.zip

Examples of java.util.zip.ZipFile


    int threadCode = Thread.currentThread().hashCode();
   
    //*-- a. unzip the OpenOffice file
    logger.info("Extracting from OpenOffice file " + ifile);
 
    ZipFile zFile;
    try
     { zFile = new ZipFile(new File(ifile)); }
    catch (IOException e)
     { logger.error("Could not open OpenOffice file " + ifile + " " + e.getMessage() );
       return; }

    //*-- b. Extract the content.xml file and write to a file
    ZipEntry zEntry = zFile.getEntry("content.xml");
    InputStream xmlStream = null; PrintWriter outp = null;
    BufferedReader iReader = null;
    String outfile = "";
    try
     {
      //*-- create an input stream for the XML file
      xmlStream = zFile.getInputStream(zEntry);
      iReader = new BufferedReader( new InputStreamReader(xmlStream, "UTF-8") );
     
      //*-- generate the output file name and dump the XML contents
      String iline; outfile = Constants.OFFICEDIR + File.separator + "TEMP_content_" + threadCode + ".xml";
     
      outp = new PrintWriter(new FileWriter(outfile));
      while ( (iline = iReader.readLine()) != null ) { outp.println(iline); }
      outp.flush();
     }
    catch (IOException e)
     { logger.error("Could not read text from OpenOffice file: " + ifile + " " + e.getMessage()); }
    finally
     {
      if (outp != null) outp.close();  
      try
       { if (iReader != null) iReader.close();
         if (xmlStream != null) xmlStream.close()
         if (zFile != null) zFile.close();    
       }
      catch (IOException exc) { logger.error("Ignore error"); }
     }

    //*-- parse the content.xml file with the SAXParser
View Full Code Here


    addFromJarButton.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent e) {
       String basePath = FileDialogs.getNewFile(frame, new File(prefs.get("workingDirectory")), ".zip,.jar",
           Globals.lang("Select a Zip-archive"), JFileChooser.CUSTOM_DIALOG, false);
       ZipFile zipFile = null;
       if (basePath != null) {
         try {
           zipFile = new ZipFile(new File(basePath), ZipFile.OPEN_READ);
         } catch (IOException exc) {
           exc.printStackTrace();
           JOptionPane.showMessageDialog(frame, Globals.lang("Could not open %0 %1", basePath + ":\n", exc.getMessage())
                                              + "\n" + Globals.lang("Have you chosen the correct package path?"));
           return;
View Full Code Here

   * The InputStream in EntryHandler is null if the current entry is a
   * directory.
   */
  public static void unzip(java.io.File file, EntryHandler entryHandler)
      throws Exception {
    ZipFile zipFile = new ZipFile(file);
    Enumeration entries = zipFile.entries();
    while (entries.hasMoreElements()) {
      ZipEntry entry = (ZipEntry) entries.nextElement();

      String entryName = entry.getName();
      if (entryName.endsWith("/")) {
        entryName = entryName.substring(0, entryName.length() - 1);
      }

      int lastSlash = entryName.lastIndexOf("/");

      String path = null;
      String filename = null;

      if (lastSlash == -1) {
        path = "";
        filename = entryName;
      } else {
        path = entryName.substring(0, lastSlash);
        filename = entryName.substring(lastSlash + 1,
            entryName.length());
      }

      InputStream inputStream = zipFile.getInputStream(entry);
      entryHandler.process(path, filename, entry.isDirectory() ? null
          : inputStream);
      inputStream.close();
    }
    zipFile.close();
  }
View Full Code Here

            return null;
        }
        InputStream inputStream = null;
        DecompiledClass decompiledClass = null;
        try {
            ZipFile zf = new ZipFile(archivePath);
            ZipEntry ze = zf.getEntry(className);
            inputStream = zf.getInputStream(ze);
            decompiledClass = decompile(source, inputStream, decompilerFlags);
        } catch (IOException e) {
            source.append(e.toString());
            BytecodeOutlinePlugin.log(e, IStatus.ERROR);
        } finally {
View Full Code Here

            files = files.substring(files.indexOf(',') + 1);
            File f = new File(file);
            if (f.isDirectory()) {
                scanDirectory("", f, suite, clazz);
            } else {
                ZipFile zip = new ZipFile(file);
                Enumeration<? extends ZipEntry> entries = zip.entries();
                while (entries.hasMoreElements()) {
                    ZipEntry e = entries.nextElement();
                    String n = e.getName();
                    String p = n.replace('/', '.');
                    if (n.endsWith(".class") && (clazz == null || p.indexOf(clazz) != -1)) {
                        n = p.substring(0, p.length() - 6);
                        if (id % parts == part) {
                            InputStream is = zip.getInputStream(e);
                            AbstractTest t = getClass().newInstance();
                            t.init(n, is);
                            suite.addTest(t);
                        }
                        ++id;
View Full Code Here

            files = files.substring(files.indexOf(',') + 1);
            File f = new File(file);
            if (f.isDirectory()) {
                scanDirectory("", f, suite, clazz);
            } else {
                ZipFile zip = new ZipFile(file);
                Enumeration<? extends ZipEntry> entries = zip.entries();
                while (entries.hasMoreElements()) {
                    ZipEntry e = entries.nextElement();
                    String n = e.getName();
                    String p = n.replace('/', '.');
                System.out.println(n+" "+clazz);
                    if (n.endsWith(".class") && (clazz == null || p.indexOf(clazz) != -1)) {
                        n = p.substring(0, p.length() - 6);
                        if (id % parts == part) {
                            JasminifierClassAdapterTest t;
                            InputStream is = zip.getInputStream(e);
                            t = new JasminifierClassAdapterTest();
                            t.init(n, is);
                            suite.addTest(t);
                        }
                        ++id;
View Full Code Here

  private TestClassLoader LOADER = new TestClassLoader();

  public void tests() throws Exception {
    if (getClassAdapter(null) != null) {
      String file = System.getProperty("java.home") + "/lib/rt.jar";
      ZipFile zip = new ZipFile(file);
      Enumeration entries = zip.entries();
      while (entries.hasMoreElements()) {
        ZipEntry e = (ZipEntry) entries.nextElement();
        String n = e.getName();
        if (n.endsWith(".class")) {
          n = n.substring(0, n.length() - 6).replace('/', '.');
          InputStream is = zip.getInputStream(e);
          ClassReader cr = new ClassReader(is);
          if (cr.readInt(4) != Opcodes.V1_6) {
            try {
              ClassWriter cw = new ClassWriter(
                  ClassWriter.COMPUTE_FRAMES);
View Full Code Here

    private static final String LABEL_FONT = "Tahoma-9";

    public static void main(final String[] args) throws IOException {
        DependencyVisitor v = new DependencyVisitor();

        ZipFile f = new ZipFile(args[0]);

        long l1 = System.currentTimeMillis();
        Enumeration< ? extends ZipEntry> en = f.entries();
        while (en.hasMoreElements()) {
            ZipEntry e = en.nextElement();
            String name = e.getName();
            if (name.endsWith(".class")) {
                new ClassReader(f.getInputStream(e)).accept(v, 0);
            }
        }
        long l2 = System.currentTimeMillis();

        Map<String, Map<String, Integer>> globals = v.getGlobals();
View Full Code Here

            String docLongTitle   = null;
            String docAuthor      = null;
            String docLanguage    = null;
           
            // opening the file as zip file
            final ZipFile zipFile = new ZipFile(dest);
            final Enumeration<? extends ZipEntry> zipEnum = zipFile.entries();
            final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
           
            // looping through all containing files
            while (zipEnum.hasMoreElements()) {
               
                // getting the next zip file entry
                final ZipEntry zipEntry= zipEnum.nextElement();
                final String entryName = zipEntry.getName();
               
                // content.xml contains the document content in xml format
                if (entryName.equals("content.xml")) {
                   
                    // create a writer for output
                    writer = new CharBuffer();
                   
                    // extract data
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    saxParser.parse(zipFileEntryStream, new ODContentHandler(writer));
               
                    // close readers and writers
                    zipFileEntryStream.close();
                    writer.close();
                   
                } else if (entryName.equals("meta.xml")) {
                    //  meta.xml contains metadata about the document
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    final ODMetaHandler metaData = new ODMetaHandler();
                    saxParser.parse(zipFileEntryStream, metaData);
                    docDescription = metaData.getDescription();
                    docKeywordStr  = metaData.getKeyword();
View Full Code Here

            String docLongTitle   = null;
            String docAuthor      = null;
            String docLanguage    = null;
           
            // opening the file as zip file
            final ZipFile zipFile= new ZipFile(dest);
            final Enumeration<? extends ZipEntry> zipEnum = zipFile.entries();
            final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
           
            // looping through all containing files
            while (zipEnum.hasMoreElements()) {
               
                // get next zip file entry
                final ZipEntry zipEntry= zipEnum.nextElement();
                final String entryName = zipEntry.getName();
               
                // content.xml contains the document content in xml format
                if (entryName.equals("word/document.xml")
                  || entryName.startsWith("ppt/slides/slide")
                  || entryName.startsWith("xl/worksheets/sheet")) {
                   
                    // create a writer for output
                    writer = new CharBuffer();
                   
                    // extract data
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    saxParser.parse(zipFileEntryStream, new ODContentHandler(writer));
               
                    // close readers and writers
                    zipFileEntryStream.close();
                    writer.close();
                   
                } else if (entryName.equals("docProps/core.xml")) {
                    //  meta.xml contains metadata about the document
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    final ODMetaHandler metaData = new ODMetaHandler();
                    saxParser.parse(zipFileEntryStream, metaData);
                    docDescription = metaData.getDescription();
                    docKeywordStr  = metaData.getKeyword();
View Full Code Here

TOP

Related Classes of java.util.zip.ZipFile

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.