01: package de.regnis.q.sequence.line;
02:
03: import java.io.*;
04: import java.util.*;
05:
06: /**
07: * @author Marc Strapetz
08: */
09: public class QSequenceLineRandomAccessFileFactory {
10:
11: // Static =================================================================
12:
13: private static final Map fileToRaFile = new HashMap();
14:
15: static {
16: Runtime.getRuntime().addShutdownHook(new Thread() {
17: public void run() {
18: for (Iterator it = fileToRaFile.keySet().iterator(); it
19: .hasNext();) {
20: final File file = (File) it.next();
21: final RandomAccessFile raFile = (RandomAccessFile) fileToRaFile
22: .get(file);
23:
24: try {
25: raFile.close();
26: file.delete();
27: } catch (IOException ex) {
28: }
29: }
30:
31: super .run();
32: }
33: });
34: }
35:
36: public static RandomAccessFile createRandomAccessFile(File file,
37: String mode) throws FileNotFoundException {
38: final RandomAccessFile raFile = new RandomAccessFile(file, mode);
39: fileToRaFile.put(file, raFile);
40: return raFile;
41: }
42: }
|