I wrote some test that zip files in some dummy directory:
public void compressFileToZipTest() throws IOException{
try (DirectoryStream<Path> stream = Files.newDirectoryStream(
Paths.get("src", "test", "resources", "dummy", "files"), new FilesFilter())){
for (Path entry: stream) {
Path dst = entry.getParent().resolve(entry.getFileName().toString() + ".zip");
boolean succeed = FilesUtility.compressToZip(entry, dst);
Assert.assertTrue("Failed to create destination file", succeed);
try(ZipFile zipFile = new ZipFile(dst.toFile())){
Assert.assertTrue("Failed to compress file size", Files.size(entry) > Files.size(dst));
}
dst.toFile().deleteOnExit();
}
}
}
private static final class FilesFilter implements DirectoryStream.Filter<Path>{
@Override
public boolean accept(Path entry) throws IOException {
return !Files.isDirectory(entry);
}
}
The test worked well until our build team changed the underlining NAS storage, this lead to infinite loop while streaming from directory and writing to it.
I will be glad if some one can explain the issue (I assume that it's related to the paths iterator implementation).