Package java.util

Examples of java.util.Formatter


*/
public class NumberRenderer implements AttributeRenderer {
    public String toString(Object o, String formatString, Locale locale) {
        // o will be instanceof Number
        if ( formatString==null ) return o.toString();
        Formatter f = new Formatter(locale);
        f.format(formatString, o);
        return f.toString();
    }
View Full Code Here


    {
        StringBuilder builder = new StringBuilder("InternalClassTransformation[\n");

        try
        {
            Formatter formatter = new Formatter(builder);

            formatter.format("%s %s extends %s", Modifier.toString(ctClass.getModifiers()), ctClass.getName(), ctClass
                    .getSuperclass().getName());

            CtClass[] interfaces = ctClass.getInterfaces();

            for (int i = 0; i < interfaces.length; i++)
            {
                if (i == 0)
                    builder.append("\n  implements ");
                else
                    builder.append(", ");

                builder.append(interfaces[i].getName());
            }

            if (description != null)
                formatter.format("\n\n%s", description.toString());
        }
        catch (NotFoundException ex)
        {
            builder.append(ex);
        }
View Full Code Here

  }
 
  protected String getAuth(String id, String pwd, String service) {
    try {
      Client client = new CommonsClient();
      Formatter f = new Formatter();
      f.format(
        "Email=%s&Passwd=%s&service=%s&source=%s",
        URLEncoder.encode(id, "utf-8"),
        URLEncoder.encode(pwd, "utf-8"),
        (service != null) ? URLEncoder.encode(service, "utf-8") : "",
        URLEncoder.encode(Version.APP_NAME, "utf-8"));
      StringRequestEntity stringreq = new StringRequestEntity(f.toString());
      String uri = "https://www.google.com/accounts/ClientLogin";
      RequestOptions options = client.getDefaultRequestOptions();
      options.setContentType("application/x-www-form-urlencoded");
      ClientResponse response = client.post(uri, stringreq, options);
      InputStream in = response.getInputStream();
View Full Code Here

        return this;
    }

    private static String toHex(ByteBuffer in)
    {
        Formatter formatter = new Formatter();
        int count = 0;
        while(in.hasRemaining())
        {
            formatter.format("%02x ", in.get() & 0xFF);
            if(count++ == 16)
            {
                formatter.format("\n");
                count = 0;
            }

        }
        return formatter.toString();
    }
View Full Code Here

                              final String description,
                              final Object... args)
    {
        Error error = new Error();
        error.setCondition(framingError);
        Formatter formatter = new Formatter();
        error.setDescription(formatter.format(description, args).toString());
        return error;
    }
View Full Code Here

  public void printStats()
  {
    if (0 == _winNum) _winNum = 1;
    long elapsedMs = _endTs - _startTs;
    Formatter fmt = new Formatter();
    fmt.format(GLOBAL_STATS_FORMAT, elapsedMs,
               _eventsNum, (1000.0 * _eventsNum / elapsedMs),
               _winNum, (1000.0 * _winNum / elapsedMs),
               _payloadBytes, (1000.0 * _payloadBytes / elapsedMs), _payloadBytes / _eventsNum,
               _eventBytes, (1000.0 * _eventBytes / elapsedMs),
               1.0 * _eventLagNs / (1000000L * _eventsNum));
    fmt.flush();
    fmt.close();
    String statsStr = fmt.toString();
    try
    {
      _out.write(statsStr.getBytes(Charset.defaultCharset()));
      _out.flush();
    }
View Full Code Here

    return path.substring(startIdx, endIdx + 1);
  }

  private void returnComponentStatus(DatabusRequest request) throws IOException
  {
    Formatter fmt = new Formatter();
    fmt.format("{\"status\":\"%s\",\"message\":\"%s\"}\n", _status.getStatus().toString(),
               _status.getMessage());
    fmt.flush();
    request.getResponseContent().write(ByteBuffer.wrap(fmt.toString().getBytes(Charset.defaultCharset())));
  }
View Full Code Here

        error = true;
        onRequestFailure(uriString.toString(), ex);
      }
    }

    Formatter uriFmt = new Formatter(uriString);
    if ( null != filterStr)
    {
      uriFmt.format("/bootstrap?sources=%s&checkPoint=%s&output=binary&batchSize=%d&filter=%s",
                  _sourcesIdList, _checkpoint.toString(), _freeBufferSpace, filterStr);
    } else {
      uriFmt.format("/bootstrap?sources=%s&checkPoint=%s&output=binary&batchSize=%d",
                _sourcesIdList, _checkpoint.toString(), _freeBufferSpace);
    }
    uriFmt.close(); //make the compiler shut up

    return error;
  }
View Full Code Here

  }

  private boolean populateStreamRequestUrl(StringBuilder uriString)
  {
    ObjectMapper objMapper = new ObjectMapper();
    Formatter uriFmt = new Formatter(uriString);
    String filtersStr = null;
    boolean error = false;
    if (null != _filter)
    {
      try
View Full Code Here

* @param in example: name=value&foo=bar#fragment
*/
  static CharSequence encodeUriQuery(CharSequence in) {
    //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things.
    StringBuilder outBuf = null;
    Formatter formatter = null;
    for(int i = 0; i < in.length(); i++) {
      char c = in.charAt(i);
      boolean escape = true;
      if (c < 128) {
        if (asciiQueryChars.get((int)c)) {
          escape = false;
        }
      } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii
        escape = false;
      }
      if (!escape) {
        if (outBuf != null)
          outBuf.append(c);
      } else {
        //escape
        if (outBuf == null) {
          outBuf = new StringBuilder(in.length() + 5*3);
          outBuf.append(in,0,i);
          formatter = new Formatter(outBuf);
        }
        //leading %, 0 padded, width 2, capital hex
        formatter.format("%%%02X",(int)c);//TODO
        formatter.close();
      }
    }
    return outBuf != null ? outBuf : in;
  }
View Full Code Here

TOP

Related Classes of java.util.Formatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.