--- dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceNS.java 2016/01/28 11:03:14 2861 +++ dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceNS.java 2016/02/03 18:45:33 2903 @@ -1,68 +1,30 @@ package dk.daoas.adressevedligehold; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.Charset; import org.apache.commons.fileupload.FileItem; import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType; -import dk.daoas.adressevedligehold.util.DeduplicateHelper; -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 { - try ( - InputStream is1 = file.getInputStream(); - InputStreamReader isr1 = new InputStreamReader(is1, Charset.forName("ISO-8859-1") ); - 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(","); - if (parts.length != 22) { - throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 22"); - } - } - - - is = file.getInputStream(); - isr = new InputStreamReader(is, Charset.forName("ISO-8859-1") ); - br = new BufferedReader(isr); + super.validatNoHeaderLine(22, ','); } //TODO: Skal csv parsning klares med Apache Commons CSV ? @@ -79,7 +41,6 @@ parts = line.split(","); if (parts.length != 22) { - System.out.println( line ); throw new IOException("Not enough fields in line " + line); } } @@ -158,21 +119,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() ); - } - - - } - }