in tooling/common/src/main/java/org/apache/karaf/minho/tooling/common/Runtime.java [309:343]
private void addZipContent(Path source, String base, ZipOutputStream target) throws Exception {
String name = source.toString().substring(base.length() + 1);
name = name.replace("\\", "/");
if (Files.isDirectory(source)) {
if (!name.endsWith("/")) {
name += "/";
}
ZipEntry entry = new JarEntry(name);
entry.setTime(Files.getLastModifiedTime(source).toMillis());
target.putNextEntry(entry);
target.closeEntry();
Files.list(source).forEach(child -> {
try {
addZipContent(child, base, target);
} catch (Exception e) {
log.warning("Can't add zip content " + e.getMessage());
}
});
} else {
ZipEntry entry = new ZipEntry(name);
entry.setTime(Files.getLastModifiedTime(source).toMillis());
target.putNextEntry(entry);
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(source.toFile()))) {
byte[] buffer = new byte[1024];
while (true) {
int count = in.read(buffer);
if (count == -1) {
break;
}
target.write(buffer, 0, count);
}
target.closeEntry();
}
}
}