@Override
public InputStream readArchiveProfile(String artifactName, String version, String profileName) throws IOException {
Path profilePath = Paths.get(profilePath(artifactName, version, profileName));
ByteArrayOutputStream os = new ByteArrayOutputStream();
TarArchiveOutputStream tarArchive = new TarArchiveOutputStream(os);
ArrayList<Path> filePathsToAdd =
java.nio.file.Files.walk(profilePath, Integer.MAX_VALUE, FileVisitOption.FOLLOW_LINKS)
.filter(path -> path.toFile().isFile())
.collect(Collectors.toCollection(ArrayList::new));
for (Path path : filePathsToAdd) {
TarArchiveEntry tarEntry = new TarArchiveEntry(path.toFile(), profilePath.relativize(path).toString());
int permissions = FileModeUtils.getFileMode(Files.getPosixFilePermissions(path));
permissions = FileModeUtils.setFileBit(permissions);
tarEntry.setMode(permissions);
tarArchive.putArchiveEntry(tarEntry);
IOUtils.copy(Files.newInputStream(path), tarArchive);
tarArchive.closeArchiveEntry();
}
tarArchive.finish();
tarArchive.close();
return new ByteArrayInputStream(os.toByteArray());
}