Example usage for java.util Formatter close

List of usage examples for java.util Formatter close

Introduction

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

Prototype

public void close() 

Source Link

Document

Closes this formatter.

Usage

From source file:com.cloud.utils.net.NetUtils.java

public static String byte2Mac(final byte[] m) {
    final StringBuilder result = new StringBuilder(17);
    final Formatter formatter = new Formatter(result);
    formatter.format("%02x:%02x:%02x:%02x:%02x:%02x", m[0], m[1], m[2], m[3], m[4], m[5]);
    formatter.close();
    return result.toString();
}

From source file:org.megam.api.http.TransportTools.java

public String toString() {
    StringBuilder strbd = new StringBuilder();
    final Formatter formatter = new Formatter(strbd);
    formatter.format("%s%n", "*----------------------------------------------*");
    formatter.format("%12s = %s%n", "url", urlString());
    formatter.format("%12s = %s%n", "pairs", pairs());
    formatter.format("%12s = %s%n", "headers", headers());
    formatter.format("%12s = %s%n", "query", isQuery());
    formatter.format("%12s = %s%n", "encoding", encoding());
    formatter.format("%12s = %s%n", "contenttype", contentType());
    formatter.format("%12s = %s%n", "contentstring", contentString());
    formatter.format("%s%n", "*----------------------------------------------*");
    formatter.close();
    return strbd.toString();
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.CFLibXmlUtil.java

public static String formatTimestamp(Calendar cal) {
    final String S_ProcName = "formatTimestamp";
    if (cal == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(CFLibXmlUtil.class, S_ProcName, 1,
                "cal");
    }/*from  ww w  .  ja  va 2 s  . c  o m*/
    StringBuffer buff = new StringBuffer();
    Formatter fmt = new Formatter(buff);
    fmt.format("%1$04d", cal.get(Calendar.YEAR));
    buff.append('-');
    fmt.format("%1$02d", cal.get(Calendar.MONTH) + 1);
    buff.append('-');
    fmt.format("%1$02d", cal.get(Calendar.DAY_OF_MONTH));
    buff.append('T');
    fmt.format("%1$02d", cal.get(Calendar.HOUR_OF_DAY));
    buff.append(':');
    fmt.format("%1$02d", cal.get(Calendar.MINUTE));
    buff.append(':');
    fmt.format("%1$02d", cal.get(Calendar.SECOND));
    String retval = buff.toString();
    fmt.close();
    return (retval);
}

From source file:org.jasig.cas.monitor.EhCacheStatistics.java

@Override
public void toString(final StringBuilder builder) {
    final String name = this.getName();
    if (StringUtils.isNotBlank(name)) {
        builder.append(name).append(':');
    }/*w w  w  .  jav a2s . co  m*/
    final int free = getPercentFree();
    final Formatter formatter = new Formatter(builder);
    if (useBytes) {
        formatter.format("%.2f", heapSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE);
        builder.append("MB heap, ");
        formatter.format("%.2f", diskSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE);
        builder.append("MB disk, ");
    } else {
        builder.append(heapSize).append(" items in heap, ");
        builder.append(diskSize).append(" items on disk, ");
    }
    formatter.format("%.2f", offHeapSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE);
    builder.append("MB off-heap, ");
    builder.append(free).append("% free, ");
    builder.append(getEvictions()).append(" evictions");
    formatter.close();
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.CFLibXmlUtil.java

public static String formatTZTime(Calendar cal) {
    final String S_ProcName = "formatTZTime";
    if (cal == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(CFLibXmlUtil.class, S_ProcName, 1,
                "cal");
    }//from   w  ww.  j  ava 2  s  .  c  o m
    StringBuffer buff = new StringBuffer();
    Formatter fmt = new Formatter(buff);
    fmt.format("%1$02d", cal.get(Calendar.HOUR_OF_DAY));
    buff.append(':');
    fmt.format("%1$02d", cal.get(Calendar.MINUTE));
    buff.append(':');
    fmt.format("%1$02d", cal.get(Calendar.SECOND));
    int tzoff = cal.getTimeZone().getRawOffset() / 60000;
    if (tzoff < 0) {
        tzoff = 0 - tzoff;
        buff.append('-');
    } else {
        buff.append('+');
    }
    int tzhour = tzoff / 60;
    int tzmin = tzoff % 60;
    if (tzhour > 12) {
        fmt.close();
        throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(CFLibXmlUtil.class, S_ProcName, 0,
                "tzhour", tzhour);
    }
    fmt.format("%1$02d", tzhour);
    buff.append(':');
    fmt.format("%1$02d", tzmin);
    String retval = buff.toString();
    fmt.close();
    return (retval);
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.CFLibXmlUtil.java

public static String formatTZDate(Calendar cal) {
    final String S_ProcName = "formatTZDate";
    if (cal == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(CFLibXmlUtil.class, S_ProcName, 1,
                "cal");
    }//from  w w w.jav a2  s  .c  o  m
    StringBuffer buff = new StringBuffer();
    Formatter fmt = new Formatter(buff);
    fmt.format("%1$04d", cal.get(Calendar.YEAR));
    buff.append('-');
    fmt.format("%1$02d", cal.get(Calendar.MONTH) + 1);
    buff.append('-');
    fmt.format("%1$02d", cal.get(Calendar.DAY_OF_MONTH));
    int tzoff = cal.getTimeZone().getRawOffset() / 60000;
    if (tzoff < 0) {
        tzoff = 0 - tzoff;
        buff.append('-');
    } else {
        buff.append('+');
    }
    int tzhour = tzoff / 60;
    int tzmin = tzoff % 60;
    if (tzhour > 12) {
        fmt.close();
        throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(CFLibXmlUtil.class, S_ProcName, 0,
                "tzhour", tzhour);
    }
    fmt.format("%1$02d", tzhour);
    buff.append(':');
    fmt.format("%1$02d", tzmin);
    String retval = buff.toString();
    fmt.close();
    return (retval);
}

From source file:edu.uga.cs.fluxbuster.features.FeatureCalculator.java

/**
 * Calculates the domains per network feature for each cluster generated
 * on a specific run date and stores them in the database.
 * /*from   w w w . j  a  v a  2 s. c  o  m*/
 * @param log_date the run date
 * @throws Exception if there is an error calculating or storing the 
 *       feature values
 */
public void updateDomainsPerNetwork(Date log_date) throws Exception {
    Map<Integer, Double> dpn = this.calculateDomainsPerNetwork(log_date,
            Integer.parseInt(properties.getProperty(DOMAINSPERNETWORK_WINDOWKEY)));
    for (int clusterid : dpn.keySet()) {
        StringBuffer querybuf = new StringBuffer();
        Formatter formatter = new Formatter(querybuf);
        formatter.format(properties.getProperty(DOMAINSPERNETWORK_QUERY3KEY), df.format(log_date),
                dpn.get(clusterid).toString(), String.valueOf(clusterid));
        dbi.executeQueryNoResult(querybuf.toString());
        formatter.close();
    }
}

From source file:edu.uga.cs.fluxbuster.features.FeatureCalculator.java

/**
 * Calculates the previous cluster ratio feature for each cluster generated
 * on a specific run date and stores them in the database.
 *
 * @param log_date the run date/*  w w w.  j a  v  a 2 s  .com*/
 * @throws SQLException if the feature values can not be stored in the database
 */
public void updatePrevClusterRatios(Date log_date) throws SQLException {
    Hashtable<Integer, List<Double>> ratios = this.calculatePrevClusterRatios(log_date,
            Integer.parseInt(properties.getProperty(PREVCLUSTER_WINDOWKEY)));
    for (int clusterid : ratios.keySet()) {
        List<Double> ratiovals = ratios.get(clusterid);
        StringBuffer querybuf = new StringBuffer();
        Formatter formatter = new Formatter(querybuf);
        formatter.format(properties.getProperty(PREVCLUSTER_QUERY4KEY), df.format(log_date),
                ratiovals.get(0).toString(), ratiovals.get(1).toString(), Integer.toString(clusterid));
        dbi.executeQueryNoResult(querybuf.toString());
        formatter.close();
    }
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.over23.Over23IndividualCandidacy.java

@Override
public void exportValues(StringBuilder result) {
    super.exportValues(result);

    Formatter formatter = new Formatter(result);
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.over23.languages.read"),
            StringUtils.isEmpty(getLanguagesRead()) ? StringUtils.EMPTY : getLanguagesRead());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.over23.languages.write"),
            StringUtils.isEmpty(getLanguagesWrite()) ? StringUtils.EMPTY : getLanguagesWrite());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.over23.languages.speak"),
            StringUtils.isEmpty(getLanguagesSpeak()) ? StringUtils.EMPTY : getLanguagesSpeak());
    formatter.close();
}

From source file:gemlite.core.internal.db.AsyncEventHelper.java

/**
 * Log the given formatted message and exception to the provided logger. The
 * format expected is the same as supported by
 * {@link String#format(String, Object...)}.
 * //w  w  w.j a v a  2 s  .  c o  m
 * @param logger
 *          the {@link Logger} to log the message to
 * @param level
 *          the {@link Level} to use for logging the message
 * @param t
 *          the exception whose backtrace is to be logged; can be null in
 *          which case it is ignored
 * @param format
 *          the message format
 * @param params
 *          the parameters to the message format
 * 
 * @see String#format(String, Object...)
 * @see Formatter#format(String, Object...)
 */
public final void logFormat(Logger logger, Level level, Throwable t, String format, Object... params) {
    StringBuilder sb = new StringBuilder();
    Formatter fmt = new Formatter(sb);
    fmt.format(format, params);
    if (t != null) {
        sb.append(": ");
        getStackTrace(t, sb);
    }
    if (Level.SEVERE.equals(level.toString()))
        logger.error(sb.toString());
    else
        logger.info(sb.toString());
    fmt.close();
}