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

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

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

revision 2838 by torben, Sun Jan 24 21:48:55 2016 UTC revision 2861 by torben, Thu Jan 28 11:03:14 2016 UTC
# Line 28  public class AddressSourceBK implements Line 28  public class AddressSourceBK implements
28                  this.file = file;                  this.file = file;
29    
30    
31                  is = file.getInputStream();  
                 isr = new InputStreamReader(is, Charset.forName("ISO-8859-1") );  
                 br = new BufferedReader(isr);  
                                   
32          }          }
33    
34          @Override          @Override
# Line 39  public class AddressSourceBK implements Line 36  public class AddressSourceBK implements
36                  return file.getName();                  return file.getName();
37          }          }
38                    
39            @Override
40            public void validate() throws IOException {
41                    try (          
42                                    InputStream is1 = file.getInputStream();
43                                    InputStreamReader isr1 = new InputStreamReader(is1, Charset.forName("ISO-8859-1") );
44                                    BufferedReader br1 = new BufferedReader(isr1)
45                            ) {
46                            String line = br1.readLine();
47                            
48                            if (line == null) {
49                                    throw new IOException("Can't read 1st line - is file empty?");
50                            }
51                            
52                            String[] parts = line.split(";");
53    
54                            if (parts.length != 13) {
55                                    throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 13");
56                            }
57                    }
58    
59                    
60                    is = file.getInputStream();
61                    isr = new InputStreamReader(is, Charset.forName("ISO-8859-1") );
62                    br = new BufferedReader(isr);
63            }
64    
65          //TODO: Skal csv parsning klares med Apache Commons CSV ?          //TODO: Skal csv parsning klares med Apache Commons CSV ?
66    
67          @Override          @Override
# Line 56  public class AddressSourceBK implements Line 79  public class AddressSourceBK implements
79                  entry.distributor = "BK";                  entry.distributor = "BK";
80                                    
81                  String[] parts = line.split(";");                  String[] parts = line.split(";");
82                    
83                    if (parts.length != 13) {
84                            throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 13");
85                    }
86                    
87                  entry.postnr = Short.parseShort( parts[0]);                  entry.postnr = Short.parseShort( parts[0]);
88                  entry.vejnavn = parts[1].replace("\"", "");                  entry.vejnavn = parts[1].replace("\"", "");
89                  entry.husnr = Short.parseShort( parts[2] );                  entry.husnr = Short.parseShort( parts[2] );
# Line 68  public class AddressSourceBK implements Line 96  public class AddressSourceBK implements
96                                    
97                  String laesnr = parts[8].replace("\"", "");                  String laesnr = parts[8].replace("\"", "");
98                                    
99                  @SuppressWarnings("unused") String distnr = parts[9].replace("\"", "");                  //String distnr = parts[9].replace("\"", ""); //Bruges ikke
100                  String foede = parts[10].replace("\"", "");                  String foede = parts[10].replace("\"", "");
101                  String jobnr = parts[11].replace("\"", "");                  String jobnr = parts[11].replace("\"", "");
102                  String tklaes = parts[12].replace("\"", "");                  String tklaes = parts[12].replace("\"", "");

Legend:
Removed from v.2838  
changed lines
  Added in v.2861

  ViewVC Help
Powered by ViewVC 1.1.20