--- dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceDAO.java 2016/01/25 21:43:59 2844 +++ dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceDAO.java 2016/01/28 16:12:28 2868 @@ -2,40 +2,22 @@ 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 AddressSourceDAO implements AddressSource { +public class AddressSourceDAO extends AbstractAddressSource { final static String DAO = "DAO"; - DeduplicateHelper dirigeringsCache = new DeduplicateHelper(); - - FileItem file; - - InputStream is; - InputStreamReader isr; - BufferedReader br; - - int lineCount = 0; public AddressSourceDAO(FileItem file) throws Exception { - this.file = file; - - + super(file); } - - @Override - public String getFilename() { - return file.getName(); - } @Override public void validate() throws IOException { @@ -45,10 +27,13 @@ br = new BufferedReader(isr); String line = br.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 != 17) { - throw new IOException("Not enough fields in CSV file. Found " + numFields + ", expected 17"); + if (parts.length != 17) { + throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 17"); } @@ -85,6 +70,10 @@ entry.distributor = DAO; String[] parts = line.split(";"); + if (parts.length != 17) { + throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 17"); + } + entry.gadeid = Integer.parseInt( parts[0] ); entry.vejnavn = parts[1]; //String stednavn = parts[2]; //Ikke brugt @@ -128,21 +117,4 @@ return DAO; } - @Override //AutoCloseable - public void close() throws Exception { - System.out.println("Closing " + DAO + " after lines " + lineCount); - try { - br.close(); - isr.close(); - is.close(); - - file.delete(); - - } catch (Exception e) { - System.out.println("Error on closing " + e.getMessage() ); - } - - - } - }