com.gisgraphy.importer

## Class ImporterHelper

- java.lang.Object
- - com.gisgraphy.importer.ImporterHelper

-     public class ImporterHelper
      extends Object

  Useful methods for importer
  Author:
    David Masclet

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `ALLCOUTRY_FILENAME` the all country dump file name
    `static FileFilter` | `countryFileFilter`
    `static String` | `EXCLUDED_README_FILENAME` The readme filename (it must not be processed)
    `static String` | `GEONAMES_COUNTRY_FILE_ACCEPT_REGEX_STRING` The regexp that every country file dump matches
    `protected static org.slf4j.Logger` | `logger`
    `static String` | `OPENSTREETMAP_US_FILE_ACCEPT_REGEX_STRING`
    `static String` | `QUATTROSHAPES_FILE_ACCEPT_REGEX_STRING`
    `static String` | `SPLITED_ALLCOUNTRIES_FILE_ACCEPT_REGEX_STRING`
    `static String` | `SPLITED_FILE_ACCEPT_REGEX_STRING`
    `static String` | `SPLITED_GEONAMES_ALTERNATENAMES_FILE_ACCEPT_REGEX_STRING`
    `static String` | `SPLITED_OPENSTREETMAP_FILE_ACCEPT_REGEX_STRING`
    `static FileFilter` | `splitedFileFilter`
    `static String` | `TAR_BZ2_FILE_ACCEPT_REGEX_STRING`
    `static String` | `ZIP_FILE_ACCEPT_REGEX_STRING` The regexp that every zipped country file dump matches

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ImporterHelper()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `checkUrl(String urlAsString)` check if an url doesn't return 200 or 3XX code
    `static boolean` | `checkUrls(List<String> urlsAsString)`
    `static Pattern` | `compileRegex(String regexp)`
    `static String[]` | `correctLastAdmCodeIfPossible(String[] fields)`
    `static void` | `download(String address, String localFileName)`
    `static String` | `formatSeconds(long secsIn)`
    `static long` | `getHttpFileSize(String URL)`
    `static File[]` | `listCountryFilesToImport(String directoryPath)`
    `static File[]` | `listSplitedFilesToImport(String directoryPath)`
    `static File[]` | `listTarFiles(String directoryPath)`
    `static File[]` | `listZipFiles(String directoryPath)`
    `static void` | `unzipFile(File file)` unzip a file in the same directory as the zipped file
    `static String[]` | `virtualizeADMD(String[] fields)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### EXCLUDED_README_FILENAME

          public static final String EXCLUDED_README_FILENAME

      The readme filename (it must not be processed)
      See Also:
        Constant Field Values

    - #### ALLCOUTRY_FILENAME

          public static final String ALLCOUTRY_FILENAME

      the all country dump file name
      See Also:
        Constant Field Values

    - #### GEONAMES_COUNTRY_FILE_ACCEPT_REGEX_STRING

          public static final String GEONAMES_COUNTRY_FILE_ACCEPT_REGEX_STRING

      The regexp that every country file dump matches
      See Also:
        Constant Field Values

    - #### OPENSTREETMAP_US_FILE_ACCEPT_REGEX_STRING

          public static final String OPENSTREETMAP_US_FILE_ACCEPT_REGEX_STRING

      See Also:
        Constant Field Values

    - #### QUATTROSHAPES_FILE_ACCEPT_REGEX_STRING

          public static final String QUATTROSHAPES_FILE_ACCEPT_REGEX_STRING

      See Also:
        Constant Field Values

    - #### SPLITED_FILE_ACCEPT_REGEX_STRING

          public static final String SPLITED_FILE_ACCEPT_REGEX_STRING

      See Also:
        Constant Field Values

    - #### SPLITED_OPENSTREETMAP_FILE_ACCEPT_REGEX_STRING

          public static final String SPLITED_OPENSTREETMAP_FILE_ACCEPT_REGEX_STRING

      See Also:
        Constant Field Values

    - #### SPLITED_GEONAMES_ALTERNATENAMES_FILE_ACCEPT_REGEX_STRING

          public static final String SPLITED_GEONAMES_ALTERNATENAMES_FILE_ACCEPT_REGEX_STRING

      See Also:
        Constant Field Values

    - #### SPLITED_ALLCOUNTRIES_FILE_ACCEPT_REGEX_STRING

          public static final String SPLITED_ALLCOUNTRIES_FILE_ACCEPT_REGEX_STRING

      See Also:
        Constant Field Values

    - #### ZIP_FILE_ACCEPT_REGEX_STRING

          public static final String ZIP_FILE_ACCEPT_REGEX_STRING

      The regexp that every zipped country file dump matches
      See Also:
        Constant Field Values

    - #### TAR_BZ2_FILE_ACCEPT_REGEX_STRING

          public static final String TAR_BZ2_FILE_ACCEPT_REGEX_STRING

      See Also:
        Constant Field Values

    - #### logger

          protected static final org.slf4j.Logger logger

    - #### countryFileFilter

          public static FileFilter countryFileFilter

    - #### splitedFileFilter

          public static FileFilter splitedFileFilter

  - ### Constructor Detail

    - #### ImporterHelper

          public ImporterHelper()

  - ### Method Detail

    - #### listCountryFilesToImport

          public static File[] listCountryFilesToImport(String directoryPath)

      Parameters:
        `directoryPath` - The directory where files are
      Returns:
        the allcountries.txt (@see ALLCOUTRY_FILENAME file if present or the list of country file to Import or an empty array if there is no file
      See Also:
        `GEONAMES_COUNTRY_FILE_ACCEPT_REGEX_STRING`

    - #### listSplitedFilesToImport

          public static File[] listSplitedFilesToImport(String directoryPath)

      Parameters:
        `directoryPath` - The directory where splited files are

    - #### listZipFiles

          public static File[] listZipFiles(String directoryPath)

      Parameters:
        `directoryPath` - The directory where Geonames files are to be downloaded in order to be processed
      Returns:
        all the zip files present in the specified directory or an empty array if there is no file
      See Also:
        `ZIP_FILE_ACCEPT_REGEX_STRING`

    - #### listTarFiles

          public static File[] listTarFiles(String directoryPath)

      Parameters:
        `directoryPath` - The directory where openstreetmap files are to be downloaded in order to be processed
      Returns:
        all the zip files present in the specified directory or an empty array if there is no file
      See Also:
        `TAR_BZ2_FILE_ACCEPT_REGEX_STRING`

    - #### getHttpFileSize

          public static long getHttpFileSize(String URL)

      Parameters:
        `URL` - the HTTP URL
      Returns:
        The size of the HTTP file using HTTP head method or -1 if error or the file doesn't exists

    - #### checkUrls

          public static boolean checkUrls(List<String> urlsAsString)

      Parameters:
        `urlsAsString` -
      Returns:
        true if ALL the url doesn't retrun 200 or 3XX code and are valids

    - #### checkUrl

          public static boolean checkUrl(String urlAsString)

      check if an url doesn't return 200 or 3XX code
      Parameters:
        `urlAsString` - the url to check
      Returns:
        true if the url exists and is valid

    - #### download

          public static void download(String address,
                      String localFileName)
                               throws FileNotFoundException

      Parameters:
        `address` - the address of the file to be downloaded
        `localFileName` - the local file name (with absolute path)
      Throws:
        `FileNotFoundException`

    - #### unzipFile

          public static void unzipFile(File file)

      unzip a file in the same directory as the zipped file
      Parameters:
        `file` - The file to unzip

    - #### virtualizeADMD

          public static String[] virtualizeADMD(String[] fields)

      Parameters:
        `fields` - the fields corresponding to a split line of the csv geonames file
      Returns:
        the modified fields whith the feature code change to ADM1,ADM2,ADM3,ADM4 according to the ADMcodes. e.g id adm1code and Adm2 code are not null : the feature code will be change to ADM2.

    - #### correctLastAdmCodeIfPossible

          public static String[] correctLastAdmCodeIfPossible(String[] fields)

    - #### compileRegex

          public static Pattern compileRegex(String regexp)

      Parameters:
        `regexp` - a regexp
      Returns:
        A `Pattern` or null if the regexp are not corrects

    - #### formatSeconds

          public static String formatSeconds(long secsIn)

      Parameters:
        `secsIn` - the number of seconds
      Returns:
        a human reading strings. example :1 hour 6 minuts 40 seconds.

Copyright © 2015. All rights reserved.