我在一些虚拟目录中编写了一些zip文件的测试:
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);
}
}
测试运行良好,直到我们的构建团队更改了下划线NAS存储,这导致无限循环,同时从目录流式传输并写入其中。
如果有人可以解释这个问题我会很高兴(我认为它与路径迭代器的实现有关)。