Skip to content

Commit

Permalink
refs #1620 - close stream after reading file
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed May 9, 2022
1 parent 2409bd4 commit 6beb8e4
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import io.swagger.models.auth.AuthorizationValue;
import io.swagger.models.refs.RefFormat;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystem;
Expand Down Expand Up @@ -138,7 +140,9 @@ public static String readExternalRef(String file, RefFormat refFormat, List<Auth
final Path pathToUse = parentDirectory.resolve(file).normalize();

if(Files.exists(pathToUse)) {
result = IOUtils.toString(new FileInputStream(pathToUse.toFile()), "UTF-8");
try(InputStream inputStream = new FileInputStream(pathToUse.toFile())){
result = IOUtils.toString(inputStream, "UTF-8");
}
} else {
String url = file;
if(url.contains("..")) {
Expand All @@ -149,7 +153,9 @@ public static String readExternalRef(String file, RefFormat refFormat, List<Auth
final Path pathToUse2 = parentDirectory.resolve(url).normalize();

if(Files.exists(pathToUse2)) {
result = IOUtils.toString(new FileInputStream(pathToUse2.toFile()), "UTF-8");
try(InputStream inputStream = new FileInputStream(pathToUse2.toFile())){
result = IOUtils.toString(inputStream, "UTF-8");
}
}
}
if (result == null){
Expand Down

0 comments on commit 6beb8e4

Please sign in to comment.