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