/[projects]/dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceDAO.java
ViewVC logotype

Diff of /dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceDAO.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2844 by torben, Mon Jan 25 21:43:59 2016 UTC revision 2868 by torben, Thu Jan 28 16:12:28 2016 UTC
# Line 2  package dk.daoas.adressevedligehold; Line 2  package dk.daoas.adressevedligehold;
2    
3  import java.io.BufferedReader;  import java.io.BufferedReader;
4  import java.io.IOException;  import java.io.IOException;
 import java.io.InputStream;  
5  import java.io.InputStreamReader;  import java.io.InputStreamReader;
6  import java.nio.charset.Charset;  import java.nio.charset.Charset;
7    
8  import org.apache.commons.fileupload.FileItem;  import org.apache.commons.fileupload.FileItem;
9    
10  import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType;  import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType;
 import dk.daoas.adressevedligehold.util.DeduplicateHelper;  
11    
12  public class AddressSourceDAO implements AddressSource {  public class AddressSourceDAO extends AbstractAddressSource {
13                    
14          final static String DAO = "DAO";          final static String DAO = "DAO";
15                    
         DeduplicateHelper<String> dirigeringsCache = new DeduplicateHelper<String>();  
           
         FileItem file;  
           
         InputStream is;  
         InputStreamReader isr;  
         BufferedReader br;  
           
         int lineCount = 0;  
16                                    
17          public AddressSourceDAO(FileItem file) throws Exception {          public AddressSourceDAO(FileItem file) throws Exception {
18                  this.file = file;                  super(file);
   
   
19    
20          }          }
   
         @Override  
         public String getFilename() {  
                 return file.getName();  
         }  
21                    
22          @Override          @Override
23          public void validate() throws IOException {          public void validate() throws IOException {
# Line 45  public class AddressSourceDAO implements Line 27  public class AddressSourceDAO implements
27                          br = new BufferedReader(isr);                          br = new BufferedReader(isr);
28                                                    
29                          String line = br.readLine();                          String line = br.readLine();
30                            if (line == null) {
31                                    throw new IOException("Can't read 1st line - is file empty?");
32                            }                      
33                            
34                          String[] parts = line.split(";");                          String[] parts = line.split(";");
35                          int numFields = parts.length;                          if (parts.length != 17) {
36                          if (numFields != 17) {                                  throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 17");
                                 throw new IOException("Not enough fields in CSV file. Found " + numFields + ", expected 17");  
37                          }                          }
38    
39    
# Line 85  public class AddressSourceDAO implements Line 70  public class AddressSourceDAO implements
70                  entry.distributor = DAO;                  entry.distributor = DAO;
71                                    
72                  String[] parts = line.split(";");                  String[] parts = line.split(";");
73                    if (parts.length != 17) {
74                            throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 17");
75                    }
76                    
77                  entry.gadeid = Integer.parseInt( parts[0] );                  entry.gadeid = Integer.parseInt( parts[0] );
78                  entry.vejnavn = parts[1];                  entry.vejnavn = parts[1];
79                  //String stednavn = parts[2]; //Ikke brugt                  //String stednavn = parts[2]; //Ikke brugt
# Line 128  public class AddressSourceDAO implements Line 117  public class AddressSourceDAO implements
117                  return DAO;                  return DAO;
118          }          }
119    
         @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() );  
                 }  
                   
                   
         }  
   
120  }  }

Legend:
Removed from v.2844  
changed lines
  Added in v.2868

  ViewVC Help
Powered by ViewVC 1.1.20