From 6a65ca13ea642bc7060cdae848bb3fa4e71576da Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 10 Aug 2023 14:45:25 +0200 Subject: [PATCH] Polish --- .../test/AbstractDockerComposeIntegrationTests.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/test/AbstractDockerComposeIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/test/AbstractDockerComposeIntegrationTests.java index b282af843d5..970d9cb9360 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/test/AbstractDockerComposeIntegrationTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/test/AbstractDockerComposeIntegrationTests.java @@ -83,9 +83,14 @@ public abstract class AbstractDockerComposeIntegrationTests { private File transformedComposeFile(File composeFile, DockerImageName imageName) { File tempComposeFile = Path.of(tempDir.toString(), composeFile.getName()).toFile(); try { - String composeFileContent = FileCopyUtils.copyToString(new FileReader(composeFile)); + String composeFileContent; + try (FileReader reader = new FileReader(composeFile)) { + composeFileContent = FileCopyUtils.copyToString(reader); + } composeFileContent = composeFileContent.replace("{imageName}", imageName.asCanonicalNameString()); - FileCopyUtils.copy(composeFileContent, new FileWriter(tempComposeFile)); + try (FileWriter writer = new FileWriter(tempComposeFile)) { + FileCopyUtils.copy(composeFileContent, writer); + } } catch (IOException ex) { fail("Error transforming Docker compose file '" + composeFile + "' to '" + tempComposeFile + "': "