1 |
package dk.daoas.adressevedligehold; |
package dk.daoas.adressevedligehold; |
2 |
|
|
|
import java.io.BufferedReader; |
|
3 |
import java.io.IOException; |
import java.io.IOException; |
|
import java.io.InputStreamReader; |
|
|
import java.nio.charset.Charset; |
|
4 |
import java.util.List; |
import java.util.List; |
5 |
|
|
6 |
import org.apache.commons.fileupload.FileItem; |
import org.apache.commons.fileupload.FileItem; |
22 |
|
|
23 |
@Override |
@Override |
24 |
public void validate() throws IOException { |
public void validate() throws IOException { |
25 |
try { |
super.validateWithHeader(9, ';'); |
|
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 |
|
|
|
|
|
} |
|
26 |
} |
} |
27 |
|
|
28 |
|
|