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(OutputStream os) 

Source Link

Document

Constructs a new formatter with the specified output stream.

Usage

From source file:mzb.Balancer.java

/**
 * Balance all namenodes.//from w  w  w.j  ava 2s.  c  o m
 * For each iteration,
 * for each namenode,
 * execute a {@link Balancer} to work through all datanodes once.  
 */
static int run(Collection<URI> namenodes, Configuration conf) throws IOException, InterruptedException {
    final long sleeptime = 2000 * conf.getLong(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY,
            DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_DEFAULT);
    LOG.info("namenodes = " + namenodes);
    //    LOG.info("p         = " + p);

    final Formatter formatter = new Formatter(System.out);
    System.out.println(
            "Time Stamp               Iteration#  Bytes Already Moved  Bytes Left To Move  Bytes Being Moved");

    final List<NameNodeConnector> connectors = new ArrayList<NameNodeConnector>(namenodes.size());
    try {
        for (URI uri : namenodes) {
            connectors.add(new NameNodeConnector(uri, conf));
        }

        boolean done = false;
        for (int iteration = 0; !done; iteration++) {
            done = true;
            Collections.shuffle(connectors);
            for (NameNodeConnector nnc : connectors) {
                final Balancer b = new Balancer(nnc, conf);
                final ReturnStatus r = b.run(iteration, formatter, conf);
                // clean all lists
                b.resetData(conf);
                if (r == ReturnStatus.IN_PROGRESS) {
                    done = false;
                } else if (r != ReturnStatus.SUCCESS) {
                    //must be an error statue, return.
                    return r.code;
                }
            }

            if (!done) {
                Thread.sleep(sleeptime);
            }
        }
    } finally {
        for (NameNodeConnector nnc : connectors) {
            nnc.close();
        }
    }
    return ReturnStatus.SUCCESS.code;
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getQuotedTZTimeString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/*from   w w w. ja  v a  2s  .c o m*/
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getQuotedTZTimestampString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//  www  .  j a  v a2s . c  o m
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getDateString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//from w  ww .j  a v a  2 s.  co  m
        StringBuffer buff = new StringBuffer();
        Formatter fmt = new Formatter(buff);
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java

public static String getQuotedTimeString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/*from  w ww .j a v  a 2s .c o  m*/
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(":");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(":");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getTimeString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/* w w w.j  av  a2s . c  o m*/
        StringBuffer buff = new StringBuffer();
        Formatter fmt = new Formatter(buff);
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java

public static String getQuotedTimestampString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//  ww  w  .  ja  v  a 2s.  c o m
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append(" ");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(":");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(":");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getTimestampString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//  w w  w. j  a v a2 s  . c  o  m
        StringBuffer buff = new StringBuffer();
        Formatter fmt = new Formatter(buff);
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java

public static String getQuotedTZDateString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//from   w ww. jav  a2s .c  o m
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append(" ");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(":");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(":");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getTZDateString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//  ww  w.  j a  va2s. co  m
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer();
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        fmt.close();
        return (buff.toString());
    }
}