Java 8 Formatter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Formatter class.

This code example shows how to use the following methods:close, flush, format, out
 
  protected void formatSeparator(Formatter formatter, String fieldSeparator)
  { 
    try 
    { 
      Appendable out = formatter.out();
      out.append(fieldSeparator);
    } 
    catch (IOException e)
    { 
      throw new IllegalStateException(e);
    } 
  } 
 
  protected void formatError(Formatter formatter)
  { 
    formatter.format(isError() ? "ERROR" : "INFO");
  } 
 
  protected void formatPath(Formatter formatter)

8
CodeRank
This code example shows how to use the following methods:flush, format, toString
This code example shows how to use the following methods:flush, format, toString
    return formatData(JSON_FORMAT);
  } 
 
  private String formatData(String formatStr)
  { 
    Formatter fmt = new Formatter();
    fmt.format(formatStr,
               _config.getCapacity(), _config.getBucketsNum(), _config.getDropNum(),
               1.0 * _addTime / (2.0 * DATA_POINTS_NUM) - _procTime / 300000.0 ,
               1.0 * _calcTime);
    fmt.flush();
    return fmt.toString();
  } 
 
  @Override 
  public String toString()
  { 
    return toJsonString(); 
  } 
 
8
CodeRank
This code example shows how to use the following methods:format
 
    public static void main(String [] args) {
        StockName sn = new StockName("HUGE", "Huge Fruit, Inc.",
                                     "Fruit Titanesque, Inc."); 
        CharBuffer cb = CharBuffer.allocate(128);
        Formatter fmt = new Formatter(cb);
 
        fmt.format("%s", sn);            //   -> "Huge Fruit, Inc."
        test(cb, "Huge Fruit, Inc.");
 
        fmt.format("%s", sn.toString()); //   -> "HUGE - Huge Fruit, Inc."
        test(cb, "HUGE - Huge Fruit, Inc.");
 
        fmt.format("%#s", sn);           //   -> "HUGE"
        test(cb, "HUGE");
 
        fmt.format("%-10.8s", sn);       //   -> "HUGE      "
        test(cb, "HUGE      ");
 
        fmt.format("%.12s", sn);         //   -> "Huge Fruit,*"

7
CodeRank
This code example shows how to use the following methods:close, flush, format, out
 
  protected void formatSeparator(Formatter formatter, String fieldSeparator)
  { 
    try 
    { 
      Appendable out = formatter.out();
      out.append(fieldSeparator);
    } 
    catch (IOException e)
    { 
      throw new IllegalStateException(e);
    } 
  } 
 
  protected void formatError(Formatter formatter)
  { 
    formatter.format(isError() ? "ERROR" : "INFO");
  } 
 
  protected void formatPath(Formatter formatter)

7
CodeRank
This code example shows how to use the following methods:format
     
    @Override 
    public MockConfigurationVO findByNameBottomUP(Long dcId, Long podId, Long clusterId, Long hostId, String name) {
    	 Transaction txn = Transaction.currentTxn();
    	StringBuilder search = new StringBuilder();
    	Formatter formatter = new Formatter(search);
    	formatter.format("select * from mockconfiguration where (name='%s') and ((data_center_id = %d and pod_id = %d and cluster_id = %d and host_id = %d)", name, dcId, podId, clusterId, hostId);
    	formatter.format(" or (data_center_id = %d and pod_id = %d and cluster_id = %d and host_id is null)", dcId, podId, clusterId);
    	formatter.format(" or (data_center_id = %d and pod_id = %d and cluster_id is null and host_id is null)", dcId, podId);
    	formatter.format(" or (data_center_id = %d and pod_id is null and cluster_id is null and host_id is null)", dcId);
    	formatter.format(" or (data_center_id is null and pod_id is null and cluster_id is null and host_id is null)) LIMIT 1");
    	 
    	PreparedStatement pstmt = null;
		try { 
			String sql = search.toString();
			pstmt = txn.prepareAutoCloseStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next()) {
                return toEntityBean(rs, false);
            } 
7
CodeRank
This code example shows how to use the following methods:close, format
 */ 
public class MockLog implements ILogger { 
  private ArrayList<String> mMessages = new ArrayList<String>();
 
  private void add(String code, String format, Object... args) {
    Formatter formatter = new Formatter();
    mMessages.add(formatter.format(code + format, args).toString());
    formatter.close();
  } 
 
  @Override 
  public void warning(@NonNull String format, Object... args) {
    add("W ", format, args);
  } 
 
  @Override 
  public void info(@NonNull String format, Object... args) {
    add("P ", format, args);
  } 
 
7
CodeRank
This code example shows how to use the following methods:
    private ZContext ctx;
    private ZMQ.Socket client;
    private long timeout = 2500;
    private int retries = 3;
    private boolean verbose;
    private Formatter log = new Formatter(System.out);
 
    public long getTimeout() { 
        return timeout;
    } 
 
    public void setTimeout(long timeout) {
        this.timeout = timeout;
    } 
 
    public int getRetries() { 
        return retries;
    } 
 
    public void setRetries(int retries) {
7
CodeRank
This code example shows how to use the following methods:format, toString
        try { 
            distroUrl = getProperty("urlRoot") + "/"
                    + getProperty("distributionName") + "-" 
                    + getProperty("distributionVersion") + "-" 
                    + getProperty("distributionClassifier") + ".zip"; 
            Formatter formatter = new Formatter();
            formatter.format("Wrapper properties file '%s' contains deprecated entries 'urlRoot', 'distributionName', 'distributionVersion' and 'distributionClassifier'. These will be removed soon. Please use '%s' instead.%n", propertiesFile, DISTRIBUTION_URL_PROPERTY);
            warningOutput.append(formatter.toString());
        } catch (Exception e) {
            //even the deprecated properties are not provided, report error: 
            reportMissingProperty(DISTRIBUTION_URL_PROPERTY);
        } 
        return new URI(distroUrl);
    } 
 
    private static void loadProperties(File propertiesFile, Properties properties) throws IOException {
        InputStream inStream = new FileInputStream(propertiesFile);
        try { 
            properties.load(inStream);
        } finally { 
7
CodeRank
This code example shows how to use the following methods:format
 
    public static void main(String [] args) {
        StockName sn = new StockName("HUGE", "Huge Fruit, Inc.",
                                     "Fruit Titanesque, Inc."); 
        CharBuffer cb = CharBuffer.allocate(128);
        Formatter fmt = new Formatter(cb);
 
        fmt.format("%s", sn);            //   -> "Huge Fruit, Inc."
        test(cb, "Huge Fruit, Inc.");
 
        fmt.format("%s", sn.toString()); //   -> "HUGE - Huge Fruit, Inc."
        test(cb, "HUGE - Huge Fruit, Inc.");
 
        fmt.format("%#s", sn);           //   -> "HUGE"
        test(cb, "HUGE");
 
        fmt.format("%-10.8s", sn);       //   -> "HUGE      "
        test(cb, "HUGE      ");
 
        fmt.format("%.12s", sn);         //   -> "Huge Fruit,*"

6
CodeRank

Related Java 8 Formatter Questions & Answers:

See Code Examples for Java 8 Formatter Methods: