diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SizeCalculatingEntryWriter.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SizeCalculatingEntryWriter.java index b46e06516ea4..1fbb23b8c502 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SizeCalculatingEntryWriter.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SizeCalculatingEntryWriter.java @@ -98,8 +98,7 @@ private static class SizeCalculatingOutputStream extends OutputStream { private OutputStream outputStream; - SizeCalculatingOutputStream() throws IOException { - this.tempFile = File.createTempFile("springboot-", "-entrycontent"); + SizeCalculatingOutputStream() { this.outputStream = new ByteArrayOutputStream(); } @@ -119,11 +118,19 @@ public void write(byte[] b, int off, int len) throws IOException { } private OutputStream convertToFileOutputStream(ByteArrayOutputStream byteArrayOutputStream) throws IOException { + initializeTempFile(); FileOutputStream fileOutputStream = new FileOutputStream(this.tempFile); StreamUtils.copy(byteArrayOutputStream.toByteArray(), fileOutputStream); return fileOutputStream; } + private void initializeTempFile() throws IOException { + if (this.tempFile == null) { + this.tempFile = File.createTempFile("springboot-", "-entrycontent"); + this.tempFile.deleteOnExit(); + } + } + @Override public void close() throws IOException { this.outputStream.close();