--- dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceFD.java 2016/01/28 11:03:14 2861 +++ dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceFD.java 2016/01/28 16:21:36 2869 @@ -1,10 +1,6 @@ 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 java.util.List; import org.apache.commons.fileupload.FileItem; @@ -12,66 +8,21 @@ import com.google.common.base.Splitter; import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType; -import dk.daoas.adressevedligehold.util.DeduplicateHelper; -public class AddressSourceFD implements AddressSource { - - - DeduplicateHelper dirigeringsCache = new DeduplicateHelper(); - - FileItem file; - - InputStream is; - InputStreamReader isr; - BufferedReader br; - - int lineCount = 0; +public class AddressSourceFD extends AbstractAddressSource { + String filenameFirst2; public AddressSourceFD(FileItem file) throws Exception { - this.file = file; + super(file); filenameFirst2 = file.getName().substring(0, 2).toUpperCase(); } - - @Override - public String getFilename() { - return file.getName(); - } @Override public void validate() throws IOException { - try { - is = file.getInputStream(); - isr = new InputStreamReader(is, Charset.forName("ISO-8859-1") ); - 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(";"); - if (parts.length != 9) { - throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 9"); - } - - - - } catch (Exception e) { - try { - br.close(); - isr.close(); - is.close(); - } catch (Exception e2) { - System.out.println("Error cleaning up resources"); - } - - throw e; // Re-throw - - } + super.validateWithHeader(9, ';'); } @@ -132,21 +83,4 @@ return "FD"; } - @Override //AutoCloseable - public void close() throws Exception { - System.out.println("Closing FD after lines " + lineCount); - try { - br.close(); - isr.close(); - is.close(); - - file.delete(); - - } catch (Exception e) { - System.out.println("Error on closing " + e.getMessage() ); - } - - - } - }