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

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

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

revision 2851 by torben, Tue Jan 26 21:34:15 2016 UTC revision 2868 by torben, Thu Jan 28 16:12:28 2016 UTC
# Line 9  import java.nio.charset.Charset; Line 9  import java.nio.charset.Charset;
9  import org.apache.commons.fileupload.FileItem;  import org.apache.commons.fileupload.FileItem;
10    
11  import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType;  import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType;
 import dk.daoas.adressevedligehold.util.DeduplicateHelper;  
 import dk.daoas.adressevedligehold.util.SafeParsers;  
12    
13  public class AddressSourceNS implements AddressSource {  public class AddressSourceNS extends AbstractAddressSource {
14                    
15          enum NextUgedag {          enum NextUgedag {
16                  MANDAG,TIRSDAG,ONSDAG,TORSDAG,FREDAG,LORDAG,SONDAG                  MANDAG,TIRSDAG,ONSDAG,TORSDAG,FREDAG,LORDAG,SONDAG
17          }          }
18                            
         DeduplicateHelper<String> dirigeringsCache = new DeduplicateHelper<String>();  
           
         FileItem file;  
           
         InputStream is;  
         InputStreamReader isr;  
         BufferedReader br;  
           
19          String parts[];          String parts[];
20                    
         int lineCount = 0;  
21                    
22          NextUgedag nextUgedag = NextUgedag.MANDAG;          NextUgedag nextUgedag = NextUgedag.MANDAG;
23                                    
24          public AddressSourceNS(FileItem file) throws Exception {          public AddressSourceNS(FileItem file) throws Exception {
25                  this.file = file;                  super(file);
26          }          }
27    
         @Override  
         public String getFilename() {  
                 return file.getName();  
         }  
28                    
29          @Override          @Override
30          public void validate() throws IOException {          public void validate() throws IOException {
# Line 49  public class AddressSourceNS implements Line 34  public class AddressSourceNS implements
34                                  BufferedReader br1 = new BufferedReader(isr1)                                  BufferedReader br1 = new BufferedReader(isr1)
35                          ) {                          ) {
36                          String line = br1.readLine();                          String line = br1.readLine();
37                            
38                            if (line == null) {
39                                    throw new IOException("Can't read 1st line - is file empty?");
40                            }      
41                            
42                          String[] parts = line.split(",");                          String[] parts = line.split(",");
43                          int numFields = parts.length;                          if (parts.length != 22) {
44                          if (numFields != 22) {                                  throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 22");
                                 throw new IOException("Not enough fields in CSV file. Found " + numFields + ", expected 22");  
45                          }                          }
46                  }                  }
47    
# Line 155  public class AddressSourceNS implements Line 144  public class AddressSourceNS implements
144                  return "NS";                  return "NS";
145          }          }
146    
         @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() );  
                 }  
                   
                   
         }  
   
147  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20