Example usage for java.io PrintStream printf

List of usage examples for java.io PrintStream printf

Introduction

In this page you can find the example usage for java.io PrintStream printf.

Prototype

public PrintStream printf(Locale l, String format, Object... args) 

Source Link

Document

A convenience method to write a formatted string to this output stream using the specified format string and arguments.

Usage

From source file:org.codice.ddf.platform.status.impl.ListApplicationCommand.java

@Override
protected Object doExecute() throws Exception {

    PrintStream console = System.out;

    ServiceReference ref = getBundleContext().getServiceReference(ApplicationService.class.getName());

    if (ref == null) {
        console.println("Application Status service is unavailable.");
        return null;
    }/*from   www.j  a  va2  s .  c  o  m*/
    try {
        ApplicationService appService = (ApplicationService) getBundleContext().getService(ref);
        if (appService == null) {
            console.println("Application Status service is unavailable.");
            return null;
        }
        Set<Application> applications = appService.getApplications();
        console.printf("%s%10s\n", "State", "Name");
        for (Application curApp : applications) {
            ApplicationStatus appStatus = appService.getApplicationStatus(curApp);
            // only show applications that have features (gets rid of repo
            // aggregator 'apps')
            if (!curApp.getFeatures().isEmpty()) {
                console.print("[");
                switch (appStatus.getState()) {
                case ACTIVE:
                    console.print(Ansi.ansi().fg(Ansi.Color.GREEN).toString());
                    break;
                case FAILED:
                    console.print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                    break;
                case INACTIVE:
                    // don't set a color
                    break;
                case UNKNOWN:
                    console.print(Ansi.ansi().fg(Ansi.Color.YELLOW).toString());
                    break;
                default:
                    break;
                }
                console.print(StringUtils.rightPad(appStatus.getState().toString(), STATUS_COLUMN_LENGTH));
                console.print(Ansi.ansi().reset().toString());
                console.println("] " + curApp.getName());
            }
        }
    } finally {
        getBundleContext().ungetService(ref);
    }
    return null;
}

From source file:com.t_oster.liblasercut.drivers.LaosCutter.java

private void loadBitmapLine(PrintStream out, List<Long> dwords) {
    out.printf("9 %s %s ", "1", "" + (dwords.size() * 32));
    for (Long d : dwords) {
        out.printf(" " + d);
    }//from   www  . ja va 2  s . c  o m
    out.printf("\n");
}

From source file:com.t_oster.liblasercut.drivers.LaosCutter.java

private void move(PrintStream out, float x, float y, double resolution) {
    out.printf("0 %d %d\n", px2steps(isFlipXaxis() ? Util.mm2px(bedWidth, resolution) - x : x, resolution),
            px2steps(isFlipYaxis() ? Util.mm2px(bedHeight, resolution) - y : y, resolution));
}

From source file:com.t_oster.liblasercut.drivers.LaosCutter.java

private void line(PrintStream out, float x, float y, double resolution) {
    out.printf("1 %d %d\n", px2steps(isFlipXaxis() ? Util.mm2px(bedWidth, resolution) - x : x, resolution),
            px2steps(isFlipYaxis() ? Util.mm2px(bedHeight, resolution) - y : y, resolution));
}

From source file:com.t_oster.liblasercut.drivers.LaosCutter.java

private void setFocus(PrintStream out, float focus) {
    if (currentFocus != focus) {
        out.printf(Locale.US, "2 %d\n", (int) (focus / this.mmPerStep));
        currentFocus = focus;// w w w.  ja v a 2  s  .  c  o  m
    }
}

From source file:org.apache.cassandra.tools.NodeCmd.java

/**
 * Write node information./*from   w  ww. ja  va  2  s.c  o  m*/
 * 
 * @param outs the stream to write to
 */
public void printInfo(PrintStream outs) {
    boolean gossipInitialized = probe.isInitialized();
    outs.println(probe.getToken());
    outs.printf("%-17s: %s%n", "Gossip active", gossipInitialized);
    outs.printf("%-17s: %s%n", "Load", probe.getLoadString());
    if (gossipInitialized)
        outs.printf("%-17s: %s%n", "Generation No", probe.getCurrentGenerationNumber());
    else
        outs.printf("%-17s: %s%n", "Generation No", 0);

    // Uptime
    long secondsUp = probe.getUptime() / 1000;
    outs.printf("%-17s: %d%n", "Uptime (seconds)", secondsUp);

    // Memory usage
    MemoryUsage heapUsage = probe.getHeapMemoryUsage();
    double memUsed = (double) heapUsage.getUsed() / (1024 * 1024);
    double memMax = (double) heapUsage.getMax() / (1024 * 1024);
    outs.printf("%-17s: %.2f / %.2f%n", "Heap Memory (MB)", memUsed, memMax);
}

From source file:com.t_oster.liblasercut.drivers.LaosCutter.java

private void setPurge(PrintStream out, boolean purge) {
    if (currentPurge == null || !currentPurge.equals(purge)) {
        out.printf(Locale.US, "7 7 %d\n", purge ? 1 : 0);
        currentPurge = purge;//  w w  w. j  a v a2  s.  c  o  m
    }
}

From source file:com.t_oster.liblasercut.drivers.LaosCutter.java

private void setVentilation(PrintStream out, boolean ventilation) {
    if (currentVentilation == null || !currentVentilation.equals(ventilation)) {
        out.printf(Locale.US, "7 6 %d\n", ventilation ? 1 : 0);
        currentVentilation = ventilation;
    }//w w  w.ja v a2  s .  c  om
}

From source file:org.rhwlab.variationalbayesian.GaussianMixture.java

public void reportMatrixArray(PrintStream str, String name, RealMatrix[] mat) {
    for (int i = 0; i < mat.length; ++i) {
        str.printf("%s %d\n", name, i);
        for (int r = 0; r < mat[i].getRowDimension(); ++r) {
            for (int c = 0; c < mat[i].getColumnDimension(); ++c) {
                str.printf(" %f", mat[i].getEntry(r, c));
            }/*from w w w.ja v  a2s  . c o  m*/
            str.println();
        }
    }
}

From source file:at.ofai.music.util.WormFileParseException.java

public void writeBeatsAsText(String fileName) throws Exception {
    PrintStream out = new PrintStream(new File(fileName));
    char separator = '\n';
    if (fileName.endsWith(".csv"))
        separator = ',';
    for (Iterator<Event> it = iterator(); it.hasNext();) {
        Event e = it.next();/*  w  w  w .java 2  s .  com*/
        out.printf("%5.3f%c", e.keyDown, it.hasNext() ? separator : '\n');
    }
    out.close();
}