Examples of JarOutputStream


Examples of java.util.jar.JarOutputStream

                throw new IOException("Can't create the file as a directory with this name already exists: " + destFile);
            }
            OutputStream out = new BufferedOutputStream(new FileOutputStream(destFile));
            ZipOutputStream zipOut;
            if (jar) {
                zipOut = new JarOutputStream(out);
            } else {
                zipOut = new ZipOutputStream(out);
            }
            if (storeOnly) {
                zipOut.setMethod(ZipOutputStream.STORED);
View Full Code Here

Examples of java.util.jar.JarOutputStream

   @throws Exception if any errors occur
   */
  protected void extractPack(String in, String out) throws Exception {
    File f = new File(in);
      FileOutputStream fostream = new FileOutputStream(out);
      JarOutputStream jostream = new JarOutputStream(fostream);

      Pack200.Unpacker unpacker = Pack200.newUnpacker();
      unpacker.unpack(f, jostream);
      jostream.close();

      // delete pack file as its no longer needed
      f.delete();
  }
View Full Code Here

Examples of java.util.jar.JarOutputStream

      attr.put(dateAttr, now);
      map.put(className+".class", attr);
  }

  final File jarFile = new File(_destDir, _jarFileName);
  final JarOutputStream jos =
      new JarOutputStream(new FileOutputStream(jarFile), manifest);
  classes = _bcelClasses.elements();
  while (classes.hasMoreElements()) {
      final JavaClass clazz = (JavaClass)classes.nextElement();
      final String className = clazz.getClassName().replace('.','/');
      jos.putNextEntry(new JarEntry(className+".class"));
      final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
      clazz.dump(out); // dump() closes it's output stream
      out.writeTo(jos);
  }
  jos.close();
    }
View Full Code Here

Examples of java.util.jar.JarOutputStream

    // Create file olatdata temporary directory
    File file = new File(WebappHelper.getUserDataRoot() + "/tmp/" + fileName);
    file.getParentFile().mkdirs();

    FileOutputStream stream = null;
    JarOutputStream out = null;
    try {
      // Open stream for jar file
      stream = new FileOutputStream(file);
      out = new JarOutputStream(stream, new Manifest());
      // Use now as last modified date of resources
      long now = System.currentTimeMillis();
      // Add all languages
      for (String langKey : languageKeys) {
        Locale locale = getLocaleOrNull(langKey);
        // Add all bundles in the current language
        for (String bundleName : I18nModule.getBundleNamesContainingI18nFiles()) {
          Properties propertyFile = getPropertiesWithoutResolvingRecursively(locale, bundleName);
          String entryFileName = bundleName.replace(".", "/") + "/" + I18N_DIRNAME + "/" + buildI18nFilename(locale);
          // Create jar entry for this path, name and last modified
          JarEntry jarEntry = new JarEntry(entryFileName);
          jarEntry.setTime(now);
          // Write properties to jar file
          out.putNextEntry(jarEntry);
          propertyFile.store(out, null);
          if (isLogDebugEnabled()) {
            logDebug("Adding file::" + entryFileName + " + to jar", null);
          }
        }
      }
      logDebug("Finished writing jar file::" + file.getAbsolutePath(), null);
    } catch (Exception e) {
      logError("Could not write jar file", e);
      return null;
    } finally {
      try {
        out.close();
        stream.close();
      } catch (IOException e) {
        logError("Could not close stream of jar file", e);
        return null;
      }
View Full Code Here

Examples of java.util.jar.JarOutputStream

      log.debug("temporary deployment file: " + tmpFile);

      JarInputStream jis = new JarInputStream(moduleArchive);

      // make sure we don't loose the manifest when creating a new JarOutputStream
      JarOutputStream jos = null;
      FileOutputStream fos = new FileOutputStream(tmpFile);
      Manifest manifest = jis.getManifest();
      if (manifest != null)
         jos = new JarOutputStream(fos, manifest);
      else jos = new JarOutputStream(fos);

      // process all modules
      TargetModuleInfo moduleInfo = new TargetModuleInfo();
      ModuleType moduleType = null;
      JarEntry entry = jis.getNextJarEntry();
      while (entry != null)
      {
         String entryName = entry.getName();

         // only process file entries
         if (entryName.endsWith("/") == false)
         {
            moduleType = ifNotNull(determineModuleType(entryName), moduleType);
           
            // process a sub module
            if (entryName.endsWith(".jar") || entryName.endsWith(".war"))
            {
               File tmpSubModule = processSubModule(entryName, jis);
               FileInputStream fis = new FileInputStream(tmpSubModule);
               JarUtils.addJarEntry(jos, entryName, fis);
               fis.close();
            }
            else
            {
               if (mapDeploymentPlan.get("!/" + entryName) == null)
                  JarUtils.addJarEntry(jos, entryName, jis);
               else log.debug("Skip entry found in deployment plan: " + entryName);
            }
         }

         entry = jis.getNextJarEntry();
      }

      // JBAS-8059: the regular jar didn't show us enough information, lets analyze the deployment plan
      for (String entryName : mapDeploymentPlan.keySet())
      {
         moduleType = determineModuleType(entryName);
         if (moduleType != null)
            break;
      }

      if (moduleType == null)
      {
         if (moduleName.endsWith(ModuleType.EAR.getModuleExtension()))
            moduleType = ModuleType.EAR;
         else if (moduleName.endsWith(ModuleType.WAR.getModuleExtension()))
            moduleType = ModuleType.WAR;
         else if (moduleName.endsWith(ModuleType.RAR.getModuleExtension()))
            moduleType = ModuleType.RAR;
         else
            throw new RuntimeException("cannot obtain module type for " + moduleName);
      }

      moduleInfo.setModuleType(moduleType);
      // there may be top level deployment plan entries, add them
      addDeploymentPlanEntry(jos, null);
      jos.close();

      // rename the deployment
      String deploymentName = tmpFile.getParent() + File.separator + metaData.getDeploymentName();
      File deployment = new File(deploymentName);
      if (deployment.exists() && deployment.delete() == false)
View Full Code Here

Examples of java.util.jar.JarOutputStream

      // now open the copy we just made and copy again entry by entry
      JarInputStream jisModule = new JarInputStream(new FileInputStream(tmpModule));
      File tmpJBossModule = getTempFile("jboss_" + entryName);
      tmpFiles.add(tmpJBossModule);
      JarOutputStream jos = null;
      fos = new FileOutputStream(tmpJBossModule);
      Manifest manifest = jisModule.getManifest();
      if (manifest != null)
         jos = new JarOutputStream(fos, manifest);
      else jos = new JarOutputStream(fos);

      // now copy entry by entry
      JarEntry entry = jisModule.getNextJarEntry();
      while (entry != null)
      {
         String subEntryName = entry.getName();
         if (mapDeploymentPlan.get(entryName + "!/" + subEntryName) == null)
            JarUtils.addJarEntry(jos, subEntryName, jisModule);
         else log.debug("Skip entry found in deployment plan: " + subEntryName);

         entry = jisModule.getNextJarEntry();
      }
      jisModule.close();

      addDeploymentPlanEntry(jos, entryName);

      jos.close();

      return tmpJBossModule;
   }
View Full Code Here

Examples of java.util.jar.JarOutputStream

            System.out.println("Skipping sealed jar: "+file);
         }
         else
         {
            FileOutputStream fos = new FileOutputStream(file);
            JarOutputStream jos = new JarOutputStream(fos, mf);
            Enumeration entries = jarFile.entries();
            while( entries.hasMoreElements() )
            {
               JarEntry entry = (JarEntry) entries.nextElement();
               String name = entry.getName();
               if( name.equals("META-INF/MANIFEST.MF") )
               {
                  continue;
               }

               JarEntry outEntry = new JarEntry(entry.getName());
               outEntry.setTime(entry.getTime());
               if( entry.getComment() != null )
                  outEntry.setComment(entry.getComment());
               jos.putNextEntry(outEntry);
               InputStream is = jarFile.getInputStream(entry);
               int bytes = is.read(buffer);
               while( bytes > 0 )
               {
                  jos.write(buffer, 0, bytes);
                  bytes = is.read(buffer);
               }
               jos.closeEntry();
            }
            jarFile.close();
            jos.close();
            tmpFile.delete();
         }

         // Calculate the md5sum
         FileInputStream fis = new FileInputStream(file);
View Full Code Here

Examples of java.util.jar.JarOutputStream

      {
         is = getFile().openStream();
         if (is instanceof JarInputStream)
         {
            JarInputStream jis = (JarInputStream)is;
            JarOutputStream os = new JarOutputStream(bos);
            JarEntry je = null;
            while ((je = jis.getNextJarEntry()) != null)
            {
               if (filter != null && filter.accept(je.getName()))
               {
                  os.putNextEntry(je);
                  VFSUtils.copyStream(jis, os);
               }
            }
            VFSUtils.safeClose(os);
         }
View Full Code Here

Examples of java.util.jar.JarOutputStream

       
        // Manifest erzeugen
        manifest = new Manifest(is);
      }
     
      JarOutputStream out = new JarOutputStream(stream, manifest);
     
      if ( this.compression != -1)
        out.setLevel(this.compression);
     
      JarEntry jarAdd;
     
      for (int i = 0; i < tobeJared.length; i++) {
       
        if ( tobeJared[i] == null )
          continue;
        if ( !tobeJared[i].exists() || tobeJared[i].isDirectory() )
          continue;
       
        // Zielpfad der Datei auf die package-Struktur reduzieren
        path = tobeJared[i].getPath().substring(this.source.length());
        path = path.replaceAll("\\\\", "/");
       
        this.log("\n adding " + path);
       
        // Add archive entry
        jarAdd = new JarEntry(path);
        jarAdd.setTime(tobeJared[i].lastModified());
        out.putNextEntry(jarAdd);
       
        // Klasse ins Archiv schreiben
        FileInputStream in = new FileInputStream(tobeJared[i]);
       
        while (true) {
         
          int nRead = in.read(buffer, 0, buffer.length);
          if ( nRead <= 0 )
            break;
         
          out.write(buffer, 0, nRead);
        }
       
        in.close();
      }
     
      out.close();
      stream.close();
     
      this.logln("\n "+tobeJared.length+" file"+ ((tobeJared.length != 1) ? "s" : "") +" added");
     
    } catch (IOException iox) {
View Full Code Here

Examples of java.util.jar.JarOutputStream

    // Namen f�r tempor�re Datei setzen
    String tempfile = jarFile.getCanonicalPath();
    tempfile = tempfile.substring(0,tempfile.length()-jarFile.getName().length())+randomName;
   
    JarInputStream jarIn = new JarInputStream(new FileInputStream(jarFile.getPath()));
    JarOutputStream jarOut = new JarOutputStream(new FileOutputStream( tempfile ), manifest);
   
    if ( this.compression != -1)
      jarOut.setLevel(this.compression);
   
    // We must write every entry from the input JAR to the output JAR, so iterate over the entries:
    // Create a read buffer to transfer data from the input
   
    byte[] buffer = new byte[4096];
    JarEntry entry;
    String path;
    Hashtable inventory = new Hashtable();
   
    int nrOfWrittenFiles = 0;
   
    // add the new files
    for (int i = 0; i < tobeJared.length; i++) {
     
      if ( tobeJared[i] == null )
        continue;
      if ( !tobeJared[i].exists() || tobeJared[i].isDirectory() )
        continue;
     
      // Zielpfad der Datei auf die package-Struktur reduzieren
      path = tobeJared[i].getPath().substring(this.source.length());
      path = path.replaceAll("\\\\", "/");
     
      // Datei ist im Original schon enthalten?
      if ( jarContent.get(path)!=null )
        this.log("\n overwriting " + path);
      else
        this.log("\n      adding " + path);
     
      // Add archive entry
      entry = new JarEntry(path);
      entry.setTime(tobeJared[i].lastModified());
      jarOut.putNextEntry(entry);
     
      // Klasse ins Archiv schreiben
      FileInputStream in = new FileInputStream(tobeJared[i]);
     
      while ( true ) {
       
        int nRead = in.read(buffer, 0, buffer.length);
        if ( nRead <= 0 )
          break;
       
        jarOut.write(buffer, 0, nRead);
      }
     
      inventory.put(entry.getName(), "notnull");
     
      in.close();
      nrOfWrittenFiles++;
    }
   
    // Iterate the entries of the original file
    while ((entry = jarIn.getNextJarEntry()) != null) {
     
      // Exclude the manifest file from the old JAR
      if ("META-INF/MANIFEST.MF".equals(entry.getName())) continue;
     
      // Datei befindet sich bereits im jar
      if ( inventory.get(entry.getName())!=null )
        continue;
     
      // Write the entry to the output JAR
      jarOut.putNextEntry(entry);
      int read;
      while ((read = jarIn.read(buffer)) != -1) {
        jarOut.write(buffer, 0, read);
      }
     
      jarOut.closeEntry();
    }
   
    // Flush and close all the streams
    jarOut.flush();
    jarOut.close();
    jarIn.close();
   
  // altes jar l�schen und neue Datei umbenennen
    File oldJar = new File(this.targetPath);
    try {
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.