@Override
    public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
                      ParseContext context) throws IOException, SAXException, TikaException {

        /*----------------configure this parser by ParseContext Object---------------------*/

        GeoParserConfig geoParserConfig = context.get(GeoParserConfig.class, defaultConfig);
        initialize(geoParserConfig);
        if (!isAvailable(geoParserConfig)) {
            return;
        }
        NameEntityExtractor extractor = null;

        try {
            extractor = new NameEntityExtractor(nameFinder);
        } catch (Exception e) {
            LOG.warn("Named Entity Extractor setup failed: {}", e.getMessage(), e);
            return;
        }

        /*----------------get locationNameEntities and best nameEntity for the
        input stream---------------------*/
        extractor.getAllNameEntitiesfromInput(stream);
        extractor.getBestNameEntity();
        ArrayList<String> locationNameEntities = extractor.locationNameEntities;
        String bestner = extractor.bestNameEntity;

        /*------------------------resolve geonames for each ner,
        store results in a hashmap---------------------*/
        Map<String, List<Location>> resolvedGeonames = searchGeoNames(locationNameEntities);

        /*----------------store locationNameEntities and their geonames in a
        geotag, each input has one geotag---------------------*/
        GeoTag geotag = new GeoTag();
        geotag.toGeoTag(resolvedGeonames, bestner);

        /* add resolved entities in metadata */

        metadata.add("Geographic_NAME", geotag.location.getName());
        metadata.add("Geographic_LONGITUDE", geotag.location.getLongitude());
        metadata.add("Geographic_LATITUDE", geotag.location.getLatitude());
        for (int i = 0; i < geotag.alternatives.size(); ++i) {
            GeoTag alter = (GeoTag) geotag.alternatives.get(i);
            metadata.add("Optional_NAME" + (i + 1), alter.location.getName());
            metadata.add("Optional_LONGITUDE" + (i + 1), alter.location.getLongitude());
            metadata.add("Optional_LATITUDE" + (i + 1), alter.location.getLatitude());
        }
    }
@Test
    public void testNulls() throws IOException, SAXException, TikaException {
        String text = "";

        Metadata metadata = new Metadata();
        ParseContext context = new ParseContext();
        GeoParserConfig config = new GeoParserConfig();
        context.set(GeoParserConfig.class, config);
        geoparser.parse(new ByteArrayInputStream(text.getBytes(UTF_8)), new BodyContentHandler(),
                metadata, context);
        assertNull(metadata.get("Geographic_NAME"));
        assertNull(metadata.get("Geographic_LONGITUDE"));
        assertNull(metadata.get("Geographic_LATITUDE"));

    }