package org.openherbarium.module.srv.imageservice.rest.endpoint.util;

import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

public class PathFinder {

  private PathFinder() {
  }

  public static Optional<Path> find(Path base, String id) {
    try {
      return Files.walk(base, 1, FileVisitOption.FOLLOW_LINKS)
          .filter(path -> path.getFileName().toString().contains(id))
          .findFirst();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return Optional.empty();
  }

}

@@ -211,16 +211,48 @@
 ptional;
+%0Aimport java.util.stream.Stream;
 %0A%0Apublic
@@ -374,22 +374,28 @@
 try 
-%7B%0A      return
+(Stream%3CPath%3E walk =
  Fil
@@ -440,27 +440,37 @@
 W_LINKS)
+) %7B
 %0A      
-    
+return walk
 .filter(
@@ -524,19 +524,8 @@
 id))
-%0A          
 .fin

Use try-with-resources