1 |
torben |
2868 |
package dk.daoas.adressevedligehold;
|
2 |
|
|
|
3 |
|
|
import java.io.BufferedReader;
|
4 |
|
|
import java.io.InputStream;
|
5 |
|
|
import java.io.InputStreamReader;
|
6 |
|
|
|
7 |
|
|
import org.apache.commons.fileupload.FileItem;
|
8 |
|
|
|
9 |
|
|
import dk.daoas.adressevedligehold.util.DeduplicateHelper;
|
10 |
|
|
|
11 |
|
|
public abstract class AbstractAddressSource implements AddressSource {
|
12 |
|
|
|
13 |
|
|
protected DeduplicateHelper<String> dirigeringsCache = new DeduplicateHelper<String>();
|
14 |
|
|
|
15 |
|
|
protected FileItem file;
|
16 |
|
|
|
17 |
|
|
protected InputStream is;
|
18 |
|
|
protected InputStreamReader isr;
|
19 |
|
|
protected BufferedReader br;
|
20 |
|
|
|
21 |
|
|
protected int lineCount = 0;
|
22 |
|
|
|
23 |
|
|
public AbstractAddressSource(FileItem file) {
|
24 |
|
|
this.file = file;
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
@Override
|
28 |
|
|
public String getFilename() {
|
29 |
|
|
// TODO Auto-generated method stub
|
30 |
|
|
return file.getName();
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
@Override //AutoCloseable
|
34 |
|
|
public void close() throws Exception {
|
35 |
|
|
System.out.println("Closing BK after lines " + lineCount);
|
36 |
|
|
try {
|
37 |
|
|
if (br != null)
|
38 |
|
|
br.close();
|
39 |
|
|
if (isr != null)
|
40 |
|
|
isr.close();
|
41 |
|
|
if (is != null)
|
42 |
|
|
is.close();
|
43 |
|
|
|
44 |
|
|
file.delete();
|
45 |
|
|
|
46 |
|
|
} catch (Exception e) {
|
47 |
|
|
System.out.println("Error on closing " + e.getMessage() );
|
48 |
|
|
}
|
49 |
|
|
}
|
50 |
|
|
}
|