in tooling/common/src/main/java/org/apache/karaf/minho/tooling/common/Runtime.java [170:204]
private void addJarContent(Path source, String base, JarOutputStream target) throws Exception {
String name = source.toString().substring(base.length() + 1);
name = name.replace("\\", "/");
if (Files.isDirectory(source)) {
if (!name.endsWith("/")) {
name += "/";
}
JarEntry entry = new JarEntry(name);
entry.setTime(Files.getLastModifiedTime(source).toMillis());
target.putNextEntry(entry);
target.closeEntry();
Files.list(source).forEach(child -> {
try {
addJarContent(child, base, target);
} catch (Exception e) {
log.warning("Can't add jar content " + e.getMessage());
}
});
} else {
JarEntry entry = new JarEntry(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();
}
}
}