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

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

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

revision 2869 by torben, Thu Jan 28 16:21:36 2016 UTC revision 2904 by torben, Wed Feb 3 18:51:36 2016 UTC
# Line 11  import org.apache.commons.fileupload.Fil Line 11  import org.apache.commons.fileupload.Fil
11    
12  import com.google.common.base.Splitter;  import com.google.common.base.Splitter;
13    
14    import dk.daoas.adressevedligehold.tasks.TaskLogger;
15  import dk.daoas.adressevedligehold.util.DeduplicateHelper;  import dk.daoas.adressevedligehold.util.DeduplicateHelper;
16    
17  public abstract class AbstractAddressSource implements AddressSource {  public abstract class AbstractAddressSource implements AddressSource {
18                    
19            private TaskLogger logger = TaskLogger.getInstance();
20            
21          protected DeduplicateHelper<String> dirigeringsCache = new DeduplicateHelper<String>();          protected DeduplicateHelper<String> dirigeringsCache = new DeduplicateHelper<String>();
22                    
23          protected FileItem file;          protected FileItem file;
# Line 37  public abstract class AbstractAddressSou Line 40  public abstract class AbstractAddressSou
40                    
41          @Override //AutoCloseable          @Override //AutoCloseable
42          public void close() throws Exception {          public void close() throws Exception {
43                  System.out.println("Closing BK after lines " + lineCount);                  logger.info("Closing BK after lines " + lineCount);
44                  try {                  try {
45                          if (br != null)                          if (br != null)
46                                  br.close();                                  br.close();
# Line 49  public abstract class AbstractAddressSou Line 52  public abstract class AbstractAddressSou
52                          file.delete();                          file.delete();
53                                                    
54                  } catch (Exception e) {                  } catch (Exception e) {
55                          System.out.println("Error on closing " + e.getMessage() );                          logger.warning("Error on closing ", e );
56                  }                        }      
57          }          }
58                    /**
59             * Reads the first line, validates that there are the expected number of fields, and then
60             * re-initilze the inputstream - this is for file formats that does not use a header line.
61             *
62             * @param exptectedFieldCount
63             * @param seperator
64             * @throws IOException
65             */
66          protected void validatNoHeaderLine(int exptectedFieldCount, char seperator) throws IOException {          protected void validatNoHeaderLine(int exptectedFieldCount, char seperator) throws IOException {
67                  try (                            try (          
68                                  InputStream is1 = file.getInputStream();                                  InputStream is1 = file.getInputStream();
# Line 77  public abstract class AbstractAddressSou Line 87  public abstract class AbstractAddressSou
87                  br = new BufferedReader(isr);                            br = new BufferedReader(isr);          
88          }          }
89                    
90            
91          protected void validateWithHeader(int expectedFieldCount, char seperator) throws IOException {          protected void validateWithHeader(int expectedFieldCount, char seperator) throws IOException {
92                  try {                  try {
93                          is = file.getInputStream();                          is = file.getInputStream();
# Line 101  public abstract class AbstractAddressSou Line 112  public abstract class AbstractAddressSou
112                                  isr.close();                                  isr.close();
113                                  is.close();                                  is.close();
114                          } catch (Exception e2) {                          } catch (Exception e2) {
115                                  System.out.println("Error cleaning up resources");                                  logger.warning("Error cleaning up resources", e2);
116                          }                          }
117                                                    
118                          throw e; // Re-throw                              throw e; // Re-throw    

Legend:
Removed from v.2869  
changed lines
  Added in v.2904

  ViewVC Help
Powered by ViewVC 1.1.20