Below code is to iterate through the list of files in a folder so as to create data in the db, but throws IllegalStateException: Iterator already obtained exception.
Flux.fromIterable(Files.newDirectoryStream(Paths.get(VIDEO_FILE_LOCATION)))
.map(file -> new VideoFile(file.getFileName()
.toString()))
.subscribe(f -> videoRepository.save(f));
Full stack
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:787) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:768) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at com.kalarikkal.KalarikkalApplication.main(Kalarikkalpplication.java:30) ~[main/:na]
Caused by: reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalStateException: Iterator already obtained
Caused by: java.lang.IllegalStateException: Iterator already obtained
Not able to correct this. Please help.