private static void readHashes(FsEntry parent, List<FsEntry> dirs) throws ProvisioningException { int dirsTotal = 0; try(DirectoryStream<Path> stream = Files.newDirectoryStream(parent.getPath())) { for(Path child : stream) { if(child.getFileName().toString().equals(Constants.HASHES)) { try(BufferedReader reader = Files.newBufferedReader(child)) { String line = reader.readLine(); while(line != null) { new FsEntry(parent, line, HashUtils.hexStringToByteArray(reader.readLine())); line = reader.readLine(); } } catch (IOException e) { throw new ProvisioningException("Failed to read hashes", e); } } else { dirs.add(new FsEntry(parent, child)); ++dirsTotal; } } } catch (IOException e) { throw new ProvisioningException("Failed to read hashes", e); } while(dirsTotal > 0) { readHashes(dirs.remove(dirs.size() - 1), dirs); --dirsTotal; } }