Example usage for java.util Locale ROOT

List of usage examples for java.util Locale ROOT

Introduction

In this page you can find the example usage for java.util Locale ROOT.

Prototype

Locale ROOT

To view the source code for java.util Locale ROOT.

Click Source Link

Document

Useful constant for the root locale.

Usage

From source file:business.security.control.OwmClient.java

/**
 * Find current city weather//w w  w .j a v a2s .c om
 *
 * @param cityId is the ID of the city
 * @throws JSONException if the response from the OWM server can't be parsed
 * @throws IOException if there's some network error or the OWM server
 * replies with a error.
 */
public StatusWeatherData currentWeatherAtCity(int cityId) throws IOException, JSONException {
    String subUrl = String.format(Locale.ROOT, "weather/city/%d?type=json", Integer.valueOf(cityId));
    JSONObject response = doQuery(subUrl);
    return new StatusWeatherData(response);
}

From source file:com.amazon.android.utils.Helpers.java

/**
 * Loads an image using Glide from a URL into an image view and crossfades it with the image
 * view's current image.//  ww w .ja v a 2s.c  o  m
 *
 * @param activity          The activity.
 * @param imageView         The image view to load the image into to.
 * @param url               The URL that points to the image to load.
 * @param crossFadeDuration The duration of the cross-fade in milliseconds.
 */
public static void loadImageWithCrossFadeTransition(Activity activity, ImageView imageView, String url,
        final int crossFadeDuration) {
    /*
     * With the Glide image managing framework, cross fade animations only take place if the
     * image is not already downloaded in cache. In order to have the cross fade animation
     * when the image is in cache, we need to make the following two calls.
     */
    Glide.with(activity).load(url).listener(new LoggingListener<>()).fitCenter()
            .error(R.drawable.browse_bg_color).placeholder(imageView.getDrawable()).crossFade().into(imageView);

    // Adding this second Glide call enables cross-fade transition even if the image is cached.
    Glide.with(activity).load(url).fitCenter().error(R.drawable.browse_bg_color)
            .placeholder(imageView.getDrawable())
            // Here we override the onResourceReady of the RequestListener to force
            // the cross fade animation.
            .listener(new RequestListener<String, GlideDrawable>() {
                @Override
                public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                        boolean isFirstResource) {

                    Log.d("GLIDE", String.format(Locale.ROOT, "onException(%s, %s, %s, %s)", e, model, target,
                            isFirstResource), e);
                    return false;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, String model,
                        Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {

                    ImageViewTarget<GlideDrawable> imageTarget = (ImageViewTarget<GlideDrawable>) target;
                    Drawable current = imageTarget.getCurrentDrawable();
                    if (current != null) {
                        TransitionDrawable transitionDrawable = new TransitionDrawable(
                                new Drawable[] { current, resource });
                        transitionDrawable.setCrossFadeEnabled(true);
                        transitionDrawable.startTransition(crossFadeDuration);
                        imageTarget.setDrawable(transitionDrawable);
                        return true;
                    } else
                        return false;
                }
            }).crossFade().into(imageView);
}

From source file:org.hawkular.metrics.clients.ptrans.fullstack.CollectdITest.java

private List<Point> getServerData() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();

    HttpURLConnection urlConnection = (HttpURLConnection) new URL(findNumericMetricsUrl).openConnection();
    urlConnection.connect();/*from  w w w.  ja  v  a  2  s  . c o m*/
    int responseCode = urlConnection.getResponseCode();
    if (responseCode != HttpURLConnection.HTTP_OK) {
        String msg = "Could not get metrics list from server: %s, %d";
        fail(String.format(Locale.ROOT, msg, findNumericMetricsUrl, responseCode));
    }
    List<String> metricNames;
    try (InputStream inputStream = urlConnection.getInputStream()) {
        TypeFactory typeFactory = objectMapper.getTypeFactory();
        CollectionType valueType = typeFactory.constructCollectionType(List.class, MetricName.class);
        List<MetricName> value = objectMapper.readValue(inputStream, valueType);
        metricNames = value.stream().map(MetricName::getId).collect(toList());
    }

    Stream<Point> points = Stream.empty();

    for (String metricName : metricNames) {
        String[] split = metricName.split("\\.");
        String type = split[split.length - 1];

        urlConnection = (HttpURLConnection) new URL(findNumericDataUrl(metricName)).openConnection();
        urlConnection.connect();
        responseCode = urlConnection.getResponseCode();
        if (responseCode != HttpURLConnection.HTTP_OK) {
            fail("Could not load metric data from server: " + responseCode);
        }

        try (InputStream inputStream = urlConnection.getInputStream()) {
            TypeFactory typeFactory = objectMapper.getTypeFactory();
            CollectionType valueType = typeFactory.constructCollectionType(List.class, MetricData.class);
            List<MetricData> data = objectMapper.readValue(inputStream, valueType);
            Stream<Point> metricPoints = data.stream()
                    .map(metricData -> new Point(type, metricData.timestamp, metricData.value));
            points = Stream.concat(points, metricPoints);
        }
    }

    return points.sorted(Comparator.comparing(Point::getType).thenComparing(Point::getTimestamp))
            .collect(toList());
}

From source file:net.radai.beanz.util.ReflectionUtil.java

public static boolean isSetter(Method method) {
    Type returnType = method.getGenericReturnType();
    if (!returnType.equals(void.class)) {
        return false; //should not return anything
    }/*from   w  w  w .  java2s .  co  m*/
    Type[] argumentTypes = method.getGenericParameterTypes();
    if (argumentTypes == null || argumentTypes.length != 1) {
        return false; //should accept exactly one argument
    }
    String name = method.getName();
    if (name.startsWith("set")) {
        if (name.length() < 4) {
            return false; //setSomething
        }
        String fourthChar = name.substring(3, 4);
        return fourthChar.toUpperCase(Locale.ROOT).equals(fourthChar); //setSomething (upper case)
    }
    return false;
}

From source file:com.digitalpebble.stormcrawler.filtering.basic.BasicURLNormalizer.java

/**
 * Remove % encoding from path segment in URL for characters which should be
 * unescaped according to <a//from w  ww.j  a  v a 2s .  co  m
 * href="https://tools.ietf.org/html/rfc3986#section-2.2">RFC3986</a>.
 */
private String unescapePath(String path) {
    StringBuilder sb = new StringBuilder();

    Matcher matcher = unescapeRulePattern.matcher(path);

    int end = -1;
    int letter;

    // Traverse over all encoded groups
    while (matcher.find()) {
        // Append everything up to this group
        sb.append(path.substring(end + 1, matcher.start()));

        // Get the integer representation of this hexadecimal encoded
        // character
        letter = Integer.valueOf(matcher.group().substring(1), 16);

        if (letter < 128 && unescapedCharacters[letter]) {
            // character should be unescaped in URLs
            sb.append(new Character((char) letter));
        } else {
            // Append the encoded character as uppercase
            sb.append(matcher.group().toUpperCase(Locale.ROOT));
        }

        end = matcher.start() + 2;
    }

    letter = path.length();

    // Append the rest if there's anything
    if (end <= letter - 1) {
        sb.append(path.substring(end + 1, letter));
    }

    // Ok!
    return sb.toString();
}

From source file:com.facebook.share.ShareApi.java

private static void handleImagesOnAction(Bundle parameters) {
    // In general, graph objects are passed by reference (ID/URL). But if this is an OG Action,
    // we need to pass the entire values of the contents of the 'image' property, as they
    // contain important metadata beyond just a URL.
    String imageStr = parameters.getString("image");
    if (imageStr != null) {
        try {/*w w  w  .j a va2  s .c  o m*/
            // Check to see if this is an json array. Will throw if not
            JSONArray images = new JSONArray(imageStr);
            for (int i = 0; i < images.length(); ++i) {
                JSONObject jsonImage = images.optJSONObject(i);
                if (jsonImage != null) {
                    putImageInBundleWithArrayFormat(parameters, i, jsonImage);
                } else {
                    // If we don't have jsonImage we probably just have a url
                    String url = images.getString(i);
                    parameters.putString(String.format(Locale.ROOT, "image[%d][url]", i), url);
                }
            }
            parameters.remove("image");
            return;
        } catch (JSONException ex) {
            // We couldn't parse the string as an array
        }

        // If the image is not in an array it might just be an single photo
        try {
            JSONObject image = new JSONObject(imageStr);
            putImageInBundleWithArrayFormat(parameters, 0, image);
            parameters.remove("image");
        } catch (JSONException exception) {
            // The image was not in array format or a json object and can be safely passed
            // without modification
        }
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest3Test.java

/**
 * @throws Exception if the test fails//from  w  ww  .j  a v a2  s  . c  om
 */
private void testMethod(final HttpMethod method) throws Exception {
    final String content = "<html><head><script>\n" + "function test() {\n" + "  var req = "
            + XMLHttpRequest2Test.XHRInstantiation_ + ";\n" + "  req.open('"
            + method.name().toLowerCase(Locale.ROOT) + "', 'foo.xml', false);\n" + "  req.send('');\n" + "}\n"
            + "</script></head>\n" + "<body onload='test()'></body></html>";

    final WebClient client = getWebClient();
    final MockWebConnection conn = new MockWebConnection();
    conn.setResponse(URL_FIRST, content);
    final URL urlPage2 = new URL(URL_FIRST + "foo.xml");
    conn.setResponse(urlPage2, "<foo/>\n", "text/xml");
    client.setWebConnection(conn);
    client.getPage(URL_FIRST);

    final WebRequest request = conn.getLastWebRequest();
    assertEquals(urlPage2, request.getUrl());
    assertSame(method, request.getHttpMethod());
}

From source file:net.pms.dlna.protocolinfo.MimeType.java

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
    result = prime * result + ((subtype == null) ? 0 : subtype.toLowerCase(Locale.ROOT).hashCode());
    result = prime * result + ((type == null) ? 0 : type.toLowerCase(Locale.ROOT).hashCode());
    return result;
}

From source file:me.ryanhamshire.PopulationDensity.DataStore.java

public void savePlayerData(OfflinePlayer player, PlayerData data) {
    //save that data in memory
    this.playerNameToPlayerDataMap.put(player.getUniqueId().toString(), data);

    BufferedWriter outStream = null;
    try {/*from   w ww .  j  a va  2s  .c  o  m*/
        //open the player's file
        File playerFile = new File(playerDataFolderPath + File.separator + player.getUniqueId().toString());
        playerFile.createNewFile();
        outStream = new BufferedWriter(new FileWriter(playerFile));

        //first line is home region coordinates
        outStream.write(data.homeRegion.toString());
        outStream.newLine();

        //second line is last disconnection date,
        //note use of the ROOT locale to avoid problems related to regional settings on the server being updated
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.ROOT);
        outStream.write(dateFormat.format(data.lastDisconnect));
        outStream.newLine();

        //third line is login priority
        outStream.write(String.valueOf(data.loginPriority));
        outStream.newLine();
    }

    //if any problem, log it
    catch (Exception e) {
        PopulationDensity.AddLogEntry("PopulationDensity: Unexpected exception saving data for player \""
                + player.getName() + "\": " + e.getMessage());
    }

    try {
        //close the file
        if (outStream != null)
            outStream.close();
    } catch (IOException exception) {
    }
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlForm.java

/**
 * Returns the charset to use for the form submission. This is the first one
 * from the list provided in {@link #getAcceptCharsetAttribute()} if any
 * or the page's charset else/*from   w w  w .  j  a  v  a 2 s.  c o  m*/
 * @return the charset to use for the form submission
 */
private String getSubmitCharset() {
    String charset = getAcceptCharsetAttribute();
    if (!charset.isEmpty()) {
        charset = charset.trim();
        return SUBMIT_CHARSET_PATTERN.matcher(charset).replaceAll("").toUpperCase(Locale.ROOT);
    }
    return getPage().getPageEncoding();
}