1

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).

Maxim Kirilov
  • 2,639
  • 24
  • 49
  • Do you have any `link` folder/files, may be this is causing the infinite loop. – pmverma Jun 04 '15 at 08:14
  • Did you solve the problem? I have the same. – Borodin.Mik Jul 16 '15 at 16:16
  • No. But as a workaround I changed my filter to exclude zip file extensions. – Maxim Kirilov Jul 18 '15 at 07:46
  • Well, obviously the zip files you create inside the same directory that you are actually scanning may appear within the `DirectoryStream` or not, depending on file ordering, update visibility and buffering state, in other words, depending on things outside your control. – Holger Sep 16 '15 at 15:59

0 Answers0