<commit_before>package com.ternaryop.phototumblrshare;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.regex.Pattern;

import org.json.JSONObject;

import android.content.Context;

import com.ternaryop.utils.JSONUtils;

/**
 * Obtain the DOM selector used to search the image contained inside a given url
 * 
 * @author dave
 * 
 */
public class ImageDOMSelectorFinder {
	private static HashMap<String, Object> domainMap = new HashMap<String, Object>();

	public ImageDOMSelectorFinder(Context context) {
		try {
			synchronized (domainMap) {
				BufferedReader bis = new BufferedReader(new InputStreamReader(context.getAssets().open("domSelectors.json")));
				StringBuilder builder = new StringBuilder();
				String line;
				while ((line = bis.readLine()) != null) {
					builder.append(line);
				}
				if (domainMap.isEmpty()) {
					domainMap.putAll(JSONUtils.toMap(new JSONObject(builder.toString())));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getSelectorFromUrl(String url) {
		for (String domainRE : domainMap.keySet()) {
			if (Pattern.compile(domainRE).matcher(url).find()) {
				return (String) domainMap.get(domainRE);
			}
		}
		return null;
	}
}<commit_msg>Protect against NPE<commit_after>package com.ternaryop.phototumblrshare;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.regex.Pattern;

import org.json.JSONObject;

import android.content.Context;

import com.ternaryop.utils.JSONUtils;

/**
 * Obtain the DOM selector used to search the image contained inside a given url
 * 
 * @author dave
 * 
 */
public class ImageDOMSelectorFinder {
	private static HashMap<String, Object> domainMap = new HashMap<String, Object>();

	public ImageDOMSelectorFinder(Context context) {
		try {
			synchronized (domainMap) {
				BufferedReader bis = new BufferedReader(new InputStreamReader(context.getAssets().open("domSelectors.json")));
				StringBuilder builder = new StringBuilder();
				String line;
				while ((line = bis.readLine()) != null) {
					builder.append(line);
				}
				if (domainMap.isEmpty()) {
					domainMap.putAll(JSONUtils.toMap(new JSONObject(builder.toString())));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getSelectorFromUrl(String url) {
		if (url != null) {
			for (String domainRE : domainMap.keySet()) {
				if (Pattern.compile(domainRE).matcher(url).find()) {
					return (String) domainMap.get(domainRE);
				}
			}
		}
		return null;
	}
}
{'fraction_non_alphanumeric': 0.12287480680061824, 'fraction_numerical': 0.0, 'mean_word_length': 4.157370517928287, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '828893', 'n_tokens_mistral': 904, 'n_tokens_neox': 797, 'n_words': 181}