List of usage examples for java.io UnsupportedEncodingException getLocalizedMessage
public String getLocalizedMessage()
From source file:net.sf.uadetector.DeviceCategoryExamplesReader.java
public static List<DeviceCategoryExample> read() { final InputStream stream = UserAgentStringParserIntegrationTest.class.getClassLoader() .getResourceAsStream(FILE);//from w w w.j a v a2s . c o m CSVParser csvParser = null; try { csvParser = new CSVParser(new InputStreamReader(stream, CHARSET)); } catch (final UnsupportedEncodingException e) { LOG.warn(e.getLocalizedMessage(), e); } final List<DeviceCategoryExample> examples = new ArrayList<DeviceCategoryExample>(2000); if (csvParser != null) { String[] line = null; int i = 0; do { try { line = csvParser.getLine(); } catch (final IOException e) { LOG.warn(e.getLocalizedMessage(), e); line = null; } if (line != null) { i++; if (line.length == 2) { examples.add(new DeviceCategoryExample(line[0], line[1])); } else { LOG.warn("Can not read device category example " + i + ", there are too few fields: " + line.length); } } } while (line != null); } return examples; }
From source file:net.sf.uadetector.OperatingSystemExamplesReader.java
public static List<OperatingSystemExample> read() { final InputStream stream = UserAgentStringParserIntegrationTest.class.getClassLoader() .getResourceAsStream(FILE);/* w ww . j av a 2 s. c o m*/ CSVParser csvParser = null; try { csvParser = new CSVParser(new InputStreamReader(stream, CHARSET)); } catch (final UnsupportedEncodingException e) { LOG.warn(e.getLocalizedMessage(), e); } final List<OperatingSystemExample> examples = new ArrayList<OperatingSystemExample>(200); if (csvParser != null) { String[] line = null; int i = 0; do { try { line = csvParser.getLine(); } catch (final IOException e) { line = null; LOG.warn(e.getLocalizedMessage(), e); } if (line != null) { i++; if (line.length == 2) { examples.add(new OperatingSystemExample(line[0], line[1])); } else { LOG.warn("Can not read operating system example " + i + ", there are too few fields: " + line.length); } } } while (line != null); } return examples; }
From source file:net.sf.uadetector.UserAgentExamplesReader.java
public static List<UserAgentExample> read() { final InputStream stream = UserAgentStringParserIntegrationTest.class.getClassLoader() .getResourceAsStream(FILE);//ww w.j ava 2 s . c om CSVParser csvParser = null; try { csvParser = new CSVParser(new InputStreamReader(stream, CHARSET)); } catch (final UnsupportedEncodingException e) { LOG.warn(e.getLocalizedMessage(), e); } final List<UserAgentExample> examples = new ArrayList<UserAgentExample>(2000); if (csvParser != null) { String[] line = null; int i = 0; do { try { line = csvParser.getLine(); } catch (final IOException e) { LOG.warn(e.getLocalizedMessage(), e); line = null; } if (line != null) { i++; if (line.length == 3) { examples.add(new UserAgentExample(line[0], line[1], line[2])); } else { LOG.warn("Can not read operating system example " + i + ", there are too few fields: " + line.length); } } } while (line != null); } return examples; }
From source file:net.sf.uadetector.OperatingSystemSampleReader.java
private static List<OperatingSystemSample> read(final String file) { final InputStream stream = UserAgentStringParserIntegrationTest.class.getClassLoader() .getResourceAsStream(file);//from ww w . j a v a 2 s .c om CSVParser csvParser = null; try { csvParser = new CSVParser(new InputStreamReader(stream, CHARSET)); } catch (final UnsupportedEncodingException e) { LOG.warn(e.getLocalizedMessage(), e); } final List<OperatingSystemSample> examples = new ArrayList<OperatingSystemSample>(); if (csvParser != null) { String[] line = null; int i = 0; do { try { line = csvParser.getLine(); } catch (final IOException e) { line = null; LOG.warn(e.getLocalizedMessage(), e); } if (line != null) { i++; if (line.length == 4) { final OperatingSystemFamily family = OperatingSystemFamily.valueOf(line[0]); final String name = line[1]; final VersionNumber version = VersionParser.parseVersion(line[2]); final String userAgent = line[3]; examples.add(new OperatingSystemSample(family, name, version, userAgent)); } else { LOG.warn("Can not read operating system example " + i + ", there are too few fields: " + line.length); } } } while (line != null); } return examples; }
From source file:jp.mixi.android.sdk.util.UrlUtils.java
/** * Bundle???/* w w w.j a v a 2s. co m*/ * * @param params ?Bundle * @return ???String */ public static String encodeUrlForBundle(Bundle params) { if (params == null) { return ""; } StringBuilder builder = new StringBuilder(); boolean first = true; for (String key : params.keySet()) { if (first) { first = false; } else { builder.append(PARAM_SEPARATOR); } try { builder.append(URLEncoder.encode(key, HTTP.UTF_8) + EQUAL + URLEncoder.encode(params.getString(key), HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getLocalizedMessage(), e); } } return builder.toString(); }
From source file:jp.mixi.android.sdk.util.UrlUtils.java
/** * ?Bundle???/*from w w w . j av a2 s . c o m*/ * * @param data ? * @return Bundle */ private static Bundle decodeUrl(String data) { Bundle bundle = new Bundle(); if (data != null) { String[] array = data.split(PARAM_SEPARATOR); for (String parameter : array) { String[] vals = parameter.split(EQUAL); if (vals.length == 2) { try { bundle.putString(URLDecoder.decode(vals[0], HTTP.UTF_8), URLDecoder.decode(vals[1], HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getLocalizedMessage(), e); } } } } return bundle; }
From source file:jp.mixi.android.sdk.util.UrlUtils.java
/** * map???//w w w . j av a 2 s. c o m * * @param params ?Map * @return ???String */ public static String encodeUrl(Map<String, String> params) { if (params == null || params.isEmpty()) { return ""; } StringBuilder builder = new StringBuilder(); boolean first = true; for (String key : params.keySet()) { if (first) { first = false; } else { builder.append(PARAM_SEPARATOR); } String value = params.get(key); if (key != null && value != null) { try { builder.append(URLEncoder.encode(key, HTTP.UTF_8) + EQUAL + URLEncoder.encode(params.get(key), HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getLocalizedMessage(), e); } } } return builder.toString(); }
From source file:dk.kk.ibikecphlib.search.HTTPAutocompleteHandler.java
public static List<JsonNode> getKortforsyningenAutocomplete(Location currentLocation, Address address) { String urlString;/*from w w w . ja va 2s . c o m*/ List<JsonNode> list = new ArrayList<JsonNode>(); try { // TODO: Get this from Config urlString = "https://kortforsyningen.kms.dk/?servicename=RestGeokeys_v2&method="; if ((address.hasHouseNumber()) && (address.hasZip()) && (address.getCity() == null || address.getCity().equals("") || address.getCity().equals(address.getStreet()))) { urlString += "vej"; // street search } else { urlString += "adresse"; // address search } // TODO: Removed a wildcard in the beginning of the search query. urlString += "&vejnavn=" + URLEncoder.encode(address.getStreet(), "UTF-8") + "*"; // urlString = "https://kortforsyningen.kms.dk/?servicename=RestGeokeys_v2&method=adresse&vejnavn=*" // + URLEncoder.encode(address.street, "UTF-8") + "*"; if (address.hasHouseNumber()) { urlString += "&husnr=" + address.getHouseNumber() + "*"; } urlString += "&geop=" + Util.limitDecimalPlaces(currentLocation.getLongitude(), 6) + "" + "," + Util.limitDecimalPlaces(currentLocation.getLatitude(), 6) + "" + "&georef=EPSG:4326&outgeoref=EPSG:4326&login=ibikecph&password=Spoiledmilk123&hits=10"; if (address.hasZip()) { urlString = urlString + "&postnr=" + address.getZip(); } if (address.hasCity() && !address.getCity().equals(address.getStreet())) { // urlString = urlString + "&by=" + URLEncoder.encode(address.city.trim(), "UTF-8") + "*"; urlString = urlString + "&postdist=*" + URLEncoder.encode(address.getCity().trim(), "UTF-8") + "*"; } urlString += "&geometry=true"; JsonNode rootNode = performGET(urlString); if (rootNode.has("features")) { JsonNode features = rootNode.get("features"); for (int i = 0; i < features.size(); i++) { if (features.get(i).has("properties") && (features.get(i).get("properties").has("vej_navn") || features.get(i).get("properties").has("navn"))) list.add(features.get(i)); } } } catch (UnsupportedEncodingException e) { if (e != null && e.getLocalizedMessage() != null) LOG.e(e.getLocalizedMessage()); } return list; }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.security.mca.internal.Utils.java
/** * Obtains a parameter with specified name from from query string. The query should be in format * param=value¶m=value ...//from w w w.ja v a2 s . c om * * @param query Queery in "url" format. * @param paramName Parameter name. * @return Parameter value, or null. */ public static String getParameterValueFromQuery(String query, String paramName) { String[] components = query.split("&"); for (String keyValuePair : components) { String[] pairComponents = keyValuePair.split("="); if (pairComponents.length == 2) { try { String key = URLDecoder.decode(pairComponents[0], "utf-8"); if (key.compareTo(paramName) == 0) { return URLDecoder.decode(pairComponents[1], "utf-8"); } } catch (UnsupportedEncodingException e) { logger.error("getParameterValueFromQuery failed with exception: " + e.getLocalizedMessage(), e); } } } return null; }
From source file:com.spoiledmilk.ibikecph.search.HTTPAutocompleteHandler.java
public static List<JsonNode> getOiorestAutocomplete(String searchText) { String urlString;/* www . ja va2 s .c o m*/ List<JsonNode> list = null; try { urlString = "http://geo.oiorest.dk/adresser.json?q=" + URLEncoder.encode(searchText, "UTF-8") + "&maxantal=50"; JsonNode rootNode = performGET(urlString); list = Util.JsonNodeToList(rootNode); } catch (UnsupportedEncodingException e) { LOG.e(e.getLocalizedMessage()); } return list; }