Skip to content

Commit

Permalink
Added support for reading zipped version of geonames files.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkatzel-home committed Jul 11, 2015
1 parent d1087ac commit 33bfc82
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/main/java/geocode/ReverseGeoCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ of this software and associated documentation files (the "Software"), to deal
package geocode;

import geocode.kdtree.KDTree;

import java.io.*;
import java.util.ArrayList;
import java.util.zip.ZipInputStream;

/**
*
Expand All @@ -42,7 +44,32 @@ public class ReverseGeoCode {
KDTree<GeoName> kdTree;

// Get placenames from http://download.geonames.org/export/dump/
/**
* Parse the zipped geonames file.
* @param zippedPlacednames a {@link ZipInputStream} zip file downloaded from http://download.geonames.org/export/dump/; can not be null.
* @param majorOnly only include major cities in KD-tree.
*
* @throws IOException if there is a problem reading the {@link ZipInputStream}.
* @throws NullPointerException if zippedPlacenames is {@code null}.
*/
public ReverseGeoCode( ZipInputStream zippedPlacednames, boolean majorOnly ) throws IOException {
zippedPlacednames.getNextEntry();
createKdTree(zippedPlacednames, majorOnly);

}
/**
* Parse the raw text geonames file.
* @param placenames the text file downloaded from http://download.geonames.org/export/dump/; can not be null.
* @param majorOnly only include major cities in KD-tree.
*
* @throws IOException if there is a problem reading the stream.
* @throws NullPointerException if zippedPlacenames is {@code null}.
*/
public ReverseGeoCode( InputStream placenames, boolean majorOnly ) throws IOException {
createKdTree(placenames, majorOnly);
}
private void createKdTree(InputStream placenames, boolean majorOnly)
throws IOException {
ArrayList<GeoName> arPlaceNames;
arPlaceNames = new ArrayList<GeoName>();
// Read the geonames file in the directory
Expand All @@ -56,10 +83,10 @@ public ReverseGeoCode( InputStream placenames, boolean majorOnly ) throws IOExce
}
}
} catch (IOException ex) {
in.close();
throw ex;
}finally{
in.close();
}
in.close();
kdTree = new KDTree<GeoName>(arPlaceNames);
}

Expand Down

0 comments on commit 33bfc82

Please sign in to comment.