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