mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #25 from overleaf/delete-temporary-files
Delete temporary files created by Tar on close
This commit is contained in:
commit
8e15d63a2f
2 changed files with 42 additions and 1 deletions
|
@ -0,0 +1,41 @@
|
|||
package uk.ac.ic.wlgitbridge.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* A {@link java.io.FileInputStream} which deletes the underlying
|
||||
* {@link java.io.File} on close.
|
||||
*
|
||||
* @author Michael Walker (barrucadu) {@literal <mike@barrucadu.co.uk>}
|
||||
*/
|
||||
public class DeletingFileInputStream extends FileInputStream {
|
||||
private File file;
|
||||
|
||||
/**
|
||||
* Creates a {@link java.io.FileInputStream} by opening a
|
||||
* connection to an actual file, the file named by the
|
||||
* {@link java.io.File} object file in the file system.
|
||||
*
|
||||
* When the {@link close} method is called, the {@code File} will
|
||||
* be deleted.
|
||||
*/
|
||||
public DeletingFileInputStream(File file) throws FileNotFoundException {
|
||||
super(file);
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes this input stream and deletes the underlying file.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
try {
|
||||
super.close();
|
||||
} finally {
|
||||
if(file != null) {
|
||||
file.delete();
|
||||
file = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ public class Tar {
|
|||
if (sizePtr != null) {
|
||||
sizePtr[0] = tmp.length();
|
||||
}
|
||||
return new FileInputStream(tmp);
|
||||
return new DeletingFileInputStream(tmp);
|
||||
}
|
||||
|
||||
public static void unzip(
|
||||
|
|
Loading…
Reference in a new issue