Q:

Spring Integration - Files.inboundAdapter, Server Error Too many files opened

Hi I am new to spring integration, and I have the below code flow that read/scan files in the directory, I am encountering server error of too many files opened.. I am wondering if the below causing the issue? 
Is the poller opening new file every time and not closing the previous files?
Thank you for the help.
@Bean
public IntegrationFlow jsonFileRefreshFlow(){
return IntegrationFlows.from(Files.inboundAdapter(new File(filePath))
    .autoCreateDirectory(true)
    .patternFilter("*.json")
    .watchEvents(FileReadingMessageSource.WatchEventType.CREATE,
      FileReadingMessageSource.WatchEventType.MODIFY)
      .useWatchService(true)
      .scanEachPoll(true)
      .preventDuplicates(false)
    e -> e.poller(Pollers.fixedDelay(1000, TimeUnit.MILLISECONDS)
    .maxMessagesPerPoll(Integer.MAX_VALUE)))
  .<File, Resource>transform(p -> new FileSystemResource(p))
  .<Resource>handle((p,h) -> {
    try{
      // process payload
    }catch (IOException ioEx){
      log.error("Error refreshing json specs {}", ioEx);
    }finally {
      try {
        p.getInputStream().close();
      } catch (IOException e) {
        log.error("error closing stream");
      }
    }
    return null;
  }).get();

A:

The framework doesn't open the file; presumably your .handle() method does; so it is responsible for closing it.

