--- dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceNS.java 2016/01/26 21:34:15 2851 +++ dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceNS.java 2016/01/28 16:12:28 2868 @@ -9,37 +9,22 @@ import org.apache.commons.fileupload.FileItem; import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType; -import dk.daoas.adressevedligehold.util.DeduplicateHelper; -import dk.daoas.adressevedligehold.util.SafeParsers; -public class AddressSourceNS implements AddressSource { +public class AddressSourceNS extends AbstractAddressSource { enum NextUgedag { MANDAG,TIRSDAG,ONSDAG,TORSDAG,FREDAG,LORDAG,SONDAG } - - DeduplicateHelper dirigeringsCache = new DeduplicateHelper(); - - FileItem file; - - InputStream is; - InputStreamReader isr; - BufferedReader br; - + String parts[]; - int lineCount = 0; NextUgedag nextUgedag = NextUgedag.MANDAG; public AddressSourceNS(FileItem file) throws Exception { - this.file = file; + super(file); } - @Override - public String getFilename() { - return file.getName(); - } @Override public void validate() throws IOException { @@ -49,10 +34,14 @@ BufferedReader br1 = new BufferedReader(isr1) ) { String line = br1.readLine(); + + if (line == null) { + throw new IOException("Can't read 1st line - is file empty?"); + } + String[] parts = line.split(","); - int numFields = parts.length; - if (numFields != 22) { - throw new IOException("Not enough fields in CSV file. Found " + numFields + ", expected 22"); + if (parts.length != 22) { + throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 22"); } } @@ -155,21 +144,4 @@ return "NS"; } - @Override //AutoCloseable - public void close() throws Exception { - System.out.println("Closing NS after lines " + lineCount); - try { - br.close(); - isr.close(); - is.close(); - - file.delete(); - - } catch (Exception e) { - System.out.println("Error on closing " + e.getMessage() ); - } - - - } - }