--- dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceBK.java 2016/01/25 21:43:59 2844 +++ dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceBK.java 2016/01/28 16:12:28 2868 @@ -9,32 +9,15 @@ 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 AddressSourceBK implements AddressSource { +public class AddressSourceBK extends AbstractAddressSource { - DeduplicateHelper dirigeringsCache = new DeduplicateHelper(); - - FileItem file; - - InputStream is; - InputStreamReader isr; - BufferedReader br; - - int lineCount = 0; public AddressSourceBK(FileItem file) throws Exception { - this.file = file; - - - + super(file); } - @Override - public String getFilename() { - return file.getName(); - } @Override public void validate() throws IOException { @@ -44,10 +27,15 @@ 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 != 13) { - throw new IOException("Not enough fields in CSV file. Found " + numFields + ", expected 13"); + + if (parts.length != 13) { + throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 13"); } } @@ -74,6 +62,11 @@ entry.distributor = "BK"; String[] parts = line.split(";"); + + if (parts.length != 13) { + throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 13"); + } + entry.postnr = Short.parseShort( parts[0]); entry.vejnavn = parts[1].replace("\"", ""); entry.husnr = Short.parseShort( parts[2] ); @@ -125,21 +118,4 @@ return "BK"; } - @Override //AutoCloseable - public void close() throws Exception { - System.out.println("Closing BK after lines " + lineCount); - try { - br.close(); - isr.close(); - is.close(); - - file.delete(); - - } catch (Exception e) { - System.out.println("Error on closing " + e.getMessage() ); - } - - - } - }