public CsvWriter(final String file) { this.writer = IOUtils.getBufferedWriter(file); final String firstLine = CsvUtils.buildCsvLine( SEP, QUOTE, LOC_ID, STREET, NUMBER, ZIP_CODE, CITY, COUNTRY, STATUS, LONG, LAT, X, Y, QUALITY, QUALITY_CODE, MAPQUEST_STREET, MAPQUEST_ZIP_CODE, MAPQUEST_CITY, MAPQUEST_COUNTRY, MAPQUEST_STATUS); try { this.writer.write(firstLine); } catch (IOException e) { throw new UncheckedIOException(e); } }
private void write( final Address address, final MapquestResult.MapquestStatus status, final MapquestResult.Result result, final Status rejectCause) { // Why do I always have to go so dirty when writing files? final String[] fields = new String[18]; for (int i = 0; i < fields.length; i++) fields[i] = ""; if (address != null) { fields[0] = address.getId() != null ? address.getId() : ""; fields[1] = address.getStreet() != null ? address.getStreet() : ""; fields[2] = address.getNumber() != null ? address.getNumber() : ""; fields[3] = address.getZipcode() != null ? address.getZipcode() : ""; fields[4] = address.getMunicipality() != null ? address.getMunicipality() : ""; fields[5] = address.getCountry() != null ? address.getCountry() : ""; } if (rejectCause != null) { fields[6] = rejectCause.toString(); } if (result != null) { fields[7] = result.getLongitude().toString(); fields[8] = result.getLatitude().toString(); final Coord wgsCoord = new Coord(result.getLongitude(), result.getLatitude()); final Coord chCoord = new WGS84toCH1903LV03().transform(wgsCoord); fields[9] = "" + chCoord.getX(); fields[10] = "" + chCoord.getY(); fields[11] = result.getGeocodeQuality().toString(); fields[12] = result.getGeocodeQualityCode(); fields[13] = result.getStreet(); fields[14] = result.getZip(); fields[15] = result.getCity(); fields[16] = result.getCountry(); fields[17] = status.toString(); } final String line = CsvUtils.buildCsvLine(SEP, QUOTE, fields); try { this.writer.newLine(); this.writer.write(line); } catch (IOException e) { throw new UncheckedIOException(e); } }
@Override public Address next() { try { if (line == null) line = reader.readLine(); } catch (IOException e) { throw new UncheckedIOException(e); } if (line == null) throw new NoSuchElementException(); final String[] fields = CsvUtils.parseCsvLine(SEP, QUOTE, line); line = null; final Address address = new Address(); address.setId(readField(fields, idIndex)); address.setStreet(readField(fields, streetIndex)); address.setNumber(readField(fields, numberIndex)); address.setZipcode(readField(fields, zipIndex)); address.setMunicipality(readField(fields, municipalityIndex)); final String country = readField(fields, countryIndex); address.setCountry(country != null ? country : "CH"); return address; }
public CsvParser(final String file) { this.reader = IOUtils.getBufferedReader(file); try { final String[] firstLine = CsvUtils.parseCsvLine(SEP, QUOTE, reader.readLine()); for (int i = 0; i < firstLine.length; i++) { if (STREET.equals(firstLine[i])) { if (streetIndex >= 0) throw new RuntimeException(); streetIndex = i; } if (NUMBER.equals(firstLine[i])) { if (numberIndex >= 0) throw new RuntimeException(); numberIndex = i; } if (ZIP_CODE.equals(firstLine[i])) { if (zipIndex >= 0) throw new RuntimeException(); zipIndex = i; } if (CITY.equals(firstLine[i])) { if (municipalityIndex >= 0) throw new RuntimeException(); municipalityIndex = i; } if (COUNTRY.equals(firstLine[i])) { if (countryIndex >= 0) throw new RuntimeException(); countryIndex = i; } if (LOC_ID.equals(firstLine[i])) { if (idIndex >= 0) throw new RuntimeException(); idIndex = i; } } } catch (IOException e) { throw new UncheckedIOException(e); } }