Skip to content

Commit

Permalink
Merge pull request #22112 from dreis2211
Browse files Browse the repository at this point in the history
* gh-22112:
  Cleanup temporary files after Maven plugin execution

Closes gh-22112
  • Loading branch information
wilkinsona committed Jul 14, 2020
2 parents 9dea67f + 021d9b5 commit 0566c29
Showing 1 changed file with 9 additions and 2 deletions.
Expand Up @@ -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();
}

Expand All @@ -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();
Expand Down

0 comments on commit 0566c29

Please sign in to comment.