Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 1f5bc6b

Browse files
committed
Make sure temp files are deleted upon VM exit.
1 parent 858c2fa commit 1f5bc6b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

api/src/main/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcessor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
public class PropertiesBasedResumableProcessor implements ResumableAsyncHandler.ResumableProcessor {
3131
private final static Logger log = LoggerFactory.getLogger(PropertiesBasedResumableProcessor.class);
3232
private final static File TMP = new File(System.getProperty("java.io.tmpdir"), "ahc");
33+
static {
34+
TMP.deleteOnExit();
35+
}
3336
private final static String storeName = "ResumableAsyncHandler.properties";
3437
private final ConcurrentHashMap<String, Long> properties = new ConcurrentHashMap<String, Long>();
3538

@@ -64,6 +67,7 @@ public void save(Map<String, Long> map) {
6467
throw new IllegalStateException("Unable to create directory: " + TMP.getAbsolutePath());
6568
}
6669
File f = new File(TMP, storeName);
70+
f.deleteOnExit();
6771
if (!f.createNewFile()) {
6872
throw new IllegalStateException("Unable to create temp file: " + f.getAbsolutePath());
6973
}
@@ -99,7 +103,9 @@ private static String append(Map.Entry<String, Long> e) {
99103
/* @Override */
100104
public Map<String, Long> load() {
101105
try {
102-
Scanner scan = new Scanner(new File(TMP, storeName), "UTF-8");
106+
File f = new File(TMP, storeName);
107+
f.deleteOnExit();
108+
Scanner scan = new Scanner(f, "UTF-8");
103109
scan.useDelimiter("[=\n]");
104110

105111
String key;

0 commit comments

Comments
 (0)