Skip to content

Commit

Permalink
Cleanup temporary files after Maven plugin execution
Browse files Browse the repository at this point in the history
  • Loading branch information
dreis2211 authored and wilkinsona committed Jul 14, 2020
1 parent 9dea67f commit 021d9b5
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 021d9b5

Please sign in to comment.