Merge pull request #21509 from dreis2211

* pr/21509:
  Avoid allocations in ConfigFileApplicationListener

Closes gh-21509
This commit is contained in:
Madhura Bhave 2020-05-20 17:38:47 -07:00
commit c308591de3
1 changed files with 1 additions and 1 deletions

View File

@ -580,10 +580,10 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
private Resource[] getResourcesFromPatternLocation(String location) throws IOException {
String directoryPath = location.substring(0, location.indexOf("*/"));
String fileName = location.substring(location.lastIndexOf("/") + 1);
Resource resource = this.resourceLoader.getResource(directoryPath);
File[] files = resource.getFile().listFiles(File::isDirectory);
if (files != null) {
String fileName = location.substring(location.lastIndexOf("/") + 1);
Arrays.sort(files, FILE_COMPARATOR);
return Arrays.stream(files).map((file) -> file.listFiles((dir, name) -> name.equals(fileName)))
.filter(Objects::nonNull).flatMap((Function<File[], Stream<File>>) Arrays::stream)