Example usage for java.util Formatter Formatter

List of usage examples for java.util Formatter Formatter

Introduction

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

Prototype

public Formatter() 

Source Link

Document

Constructs a new formatter.

Usage

From source file:com.lightbox.android.bitmap.BitmapUtils.java

private static String getMD5String(byte[] data) {
    MessageDigest md5 = null;/*from  ww w.  j  a  v  a 2 s  .c  o m*/
    try {
        md5 = MessageDigest.getInstance("MD5");
        md5.reset();
        md5.update(data);
        byte[] md5Hash = md5.digest();
        Formatter formatter = new Formatter();
        for (byte b : md5Hash) {
            formatter.format("%02x", b);
        }
        return formatter.toString();
    } catch (NoSuchAlgorithmException e1) {
        Log.w(TAG, e1);
    }

    return "";
}

From source file:it.geosolutions.android.map.geostore.fragment.GeoStoreResourceListFragment.java

/**
 * Update the info about pagination and visibility of more button
 *//* w  w w .j a v a  2 s  .  c om*/
private void updateView() {
    int count = adapter.getCount();
    if (loader != null) {
        TextView infoView = (TextView) getView().findViewById(R.id.info);

        Formatter f = new Formatter();
        String info = f.format(getString(R.string.geostore_info_format), count, loader.totalCount).toString();
        f.close();
        infoView.setText(info);
        //      if(count < loader.totalCount){
        //         moreButton.setVisibility(Button.VISIBLE);
        //      }
    }

}

From source file:integration.DeleteServiceFilesTest.java

/**
 * Forms a path depending on the type of file to be deleted
 * and its id.//from  w  ww . j ava  2s . c o  m
 * 
 * @param dataDir The path to the directory
 * @param klass The type of object to handle.
 * @param id The identifier of the object.
 */
private String getPath(String klass, Long id) throws Exception {
    String suffix = "";
    String prefix = "";
    Long remaining = id;
    Long dirno = 0L;

    if (id == null) {
        throw new NullPointerException("Expecting a not-null id.");
    }

    if (klass.equals(REF_ORIGINAL_FILE)) {
        prefix = FilenameUtils.concat(dataDir, "Files");
    } else if (klass.equals(REF_PIXELS)) {
        prefix = FilenameUtils.concat(dataDir, "Pixels");
    } else if (klass.equals(REF_THUMBNAIL)) {
        prefix = FilenameUtils.concat(dataDir, "Thumbnails");
    } else {
        throw new Exception("Unknown class: " + klass);
    }

    while (remaining > 999) {
        remaining /= 1000;

        if (remaining > 0) {
            Formatter formatter = new Formatter();
            dirno = remaining % 1000;
            suffix = formatter.format("Dir-%03d", dirno).out().toString() + File.separator + suffix;
        }
    }

    String path = FilenameUtils.concat(prefix, suffix + id);
    return path;
}

From source file:com.zimbra.cs.util.ProxyConfOverride.java

public String formatString(Object o) {
    Formatter f = new Formatter();
    f.format("%s", o);
    return f.toString();
}

From source file:com.github.fge.jsonschema.core.report.ProcessingMessage.java

private void addArgument(final String key, final Object value) {
    if (key != null)
        args.add(value);//from   w w w . ja  v a 2  s . c om
    if (!map.containsKey("message"))
        return;
    final String fmt = map.get("message").textValue();
    try {
        final String formatted = new Formatter().format(fmt, args.toArray()).toString();
        map.put("message", FACTORY.textNode(formatted));
    } catch (IllegalFormatException ignored) {
    }
}

From source file:de.uzk.hki.da.pkg.MetsConsistencyChecker.java

/**
 * Byte array2 hex./*from  w  w  w. java 2  s  .  c  om*/
 *
 * @param hash the hash
 * @return the string
 */
private static String byteArray2Hex(byte[] hash) {
    Formatter formatter = new Formatter();
    for (byte b : hash) {
        formatter.format("%02x", b);
    }

    String result = formatter.toString();
    formatter.close();
    return result;
}

From source file:eu.stratosphere.pact.runtime.hash.HashFunctionCollisionBenchmark.java

private void printStatistics() {
    for (int level = 0; level < maxLevel; level++) {
        int bucketCountInLevel = 0;

        SortedMap<Integer, Integer> levelMap = bucketSizesPerLevel.get(level);
        Iterator<Integer> bucketSizeIterator = levelMap.keySet().iterator();

        LOG.debug("Statistics for level: " + level);
        LOG.debug("----------------------------------------------");
        LOG.debug("");
        LOG.debug("Bucket Size |      Count");
        LOG.debug("------------------------");

        int i = 0;
        while (bucketSizeIterator.hasNext()) {
            int bucketSize = bucketSizeIterator.next();
            if (bucketSize != 0) {
                int countForBucketSize = levelMap.get(bucketSize);
                bucketCountInLevel += countForBucketSize;
                Formatter formatter = new Formatter();
                formatter.format(" %10d | %10d", bucketSize, countForBucketSize);

                if (levelMap.size() < 20 || i < 3 || i >= (levelMap.size() - 3)) {
                    LOG.debug(formatter.out());
                } else if (levelMap.size() / 2 == i) {
                    LOG.debug("         .. |         ..");
                    LOG.debug(formatter.out());
                    LOG.debug("         .. |         ..");
                }//  w w w.j  a v a 2  s  .  c o  m
                i++;
                formatter.close();
            }
        }

        LOG.debug("");
        LOG.debug("Number of non-empty buckets in level: " + bucketCountInLevel);
        LOG.debug("Number of empty buckets in level    : " + levelMap.get(0));
        LOG.debug("Number of different bucket sizes    : " + (levelMap.size() - 1));
        LOG.debug("");
        LOG.debug("");
        LOG.debug("");
    }
}

From source file:com.tulskiy.musique.system.configuration.Configuration.java

public void setColor(String key, Color value) {
    if (value == null)
        remove(key);// w ww .  ja  v a2s  . c om
    else {
        String s = new Formatter().format("#%06X", value.getRGB() & 0xFFFFFF).toString();
        put(key, s);
    }
}

From source file:eu.stratosphere.pact.runtime.hash.MultiLevelHashITCase.java

private void printStatistics() {
    for (int level = 0; level < maxLevel; level++) {
        int bucketCountInLevel = 0;

        SortedMap<Integer, Integer> levelMap = bucketSizesPerLevel.get(level);
        Iterator<Integer> bucketSizeIterator = levelMap.keySet().iterator();

        LOG.debug("Statistics for level: " + level);
        LOG.debug("----------------------------------------------");
        LOG.debug("");
        LOG.debug("Bucket Size |      Count");
        LOG.debug("------------------------");

        int i = 0;
        while (bucketSizeIterator.hasNext()) {
            int bucketSize = bucketSizeIterator.next();
            if (bucketSize != 0) {
                int countForBucketSize = levelMap.get(bucketSize);
                bucketCountInLevel += countForBucketSize;
                Formatter formatter = new Formatter();
                formatter.format(" %10d | %10d", bucketSize, countForBucketSize);

                if (levelMap.size() < 20 || i < 3 || i >= (levelMap.size() - 3)) {
                    LOG.debug(formatter.out());
                } else if (levelMap.size() / 2 == i) {
                    LOG.debug("         .. |         ..");
                    LOG.debug(formatter.out());
                    LOG.debug("         .. |         ..");
                }/*from   w w  w. j a v  a  2  s .c  o m*/
                i++;
            }
        }

        LOG.debug("");
        LOG.debug("Number of non-empty buckets in level: " + bucketCountInLevel);
        LOG.debug("Number of empty buckets in level    : " + levelMap.get(0));
        LOG.debug("Number of different bucket sizes    : " + (levelMap.size() - 1));
        LOG.debug("");
        LOG.debug("");
        LOG.debug("");
    }
}

From source file:com.zimbra.cs.util.ProxyConfOverride.java

public String formatTime(Object o) {
    Formatter f = new Formatter();
    f.format("%dms", (Long) o);
    return f.toString();
}