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(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.rhwlab.variationalbayesian.SuperVoxelGaussianMixture.java

public void reportMatrix(PrintStream str, String name, RealMatrix mat) {
    str.printf("%s\n", name);
    for (int r = 0; r < mat.getRowDimension(); ++r) {
        for (int c = 0; c < mat.getColumnDimension(); ++c) {
            str.printf(" %f", mat.getEntry(r, c));
        }/*ww  w  .ja va  2 s.c  om*/
        str.println();
    }
}

From source file:org.rhwlab.dispim.nucleus.Nucleus.java

private void reportMatrix(PrintStream stream, String label, RealMatrix m) {
    stream.printf("%s: ", label);
    for (int r = 0; r < m.getRowDimension(); ++r) {
        for (int c = 0; c < m.getColumnDimension(); ++c) {
            stream.printf("%f ", m.getEntry(r, c));
        }/*from   w  w w .  j  a  va 2  s .  c  om*/
        stream.print(" : ");
    }
    stream.println();
}

From source file:org.kuali.kfs.module.tem.batch.service.impl.TemProfileExportServiceImpl.java

public void exportProfile() {
    List<TemProfile> profiles = temProfileService.getAllActiveTemProfile();

    //Accessing EXPORT_FILE_FORMAT sys param for export file extension
    LOG.info("Accessing EXPORT_FILE_FORMAT system parameter for file extension");
    String extension = parameterService.getParameterValueAsString(TemProfileExportStep.class,
            TemConstants.TemProfileParameters.EXPORT_FILE_FORMAT);

    //Creating export file name
    String exportFile = fileDirectoryName + File.separator + fileName + "." + extension;

    //Initializing the output stream
    PrintStream OUTPUT_GLE_FILE_ps = null;
    try {//from   w w w  .j ava2  s.  c  o m
        OUTPUT_GLE_FILE_ps = new PrintStream(exportFile);
    } catch (FileNotFoundException ex) {
        throw new RuntimeException(ex.toString(), ex);
    }

    //Create file based on extension
    if (extension.equalsIgnoreCase("xml")) {
        try {
            OUTPUT_GLE_FILE_ps.printf("%s\n", generateXMLDoc(profiles));
        } catch (ParserConfigurationException ex) {
            throw new RuntimeException(ex.toString(), ex);
        } catch (TransformerException ex) {
            throw new RuntimeException(ex.toString(), ex);
        }
    } else {
        OUTPUT_GLE_FILE_ps.printf("%s\n",
                dateTimeService.toDateTimeString(dateTimeService.getCurrentDate()) + ","
                        + parameterService.getParameterValueAsString(
                                KfsParameterConstants.FINANCIAL_SYSTEM_ALL.class,
                                KfsParameterConstants.INSTITUTION_NAME));
        for (TemProfile profile : profiles) {
            try {
                OUTPUT_GLE_FILE_ps.printf("%s\n", generateCSVEntry(profile));
            } catch (Exception e) {
                throw new RuntimeException(e.toString(), e);
            }
        }
    }

    OUTPUT_GLE_FILE_ps.close();
}

From source file:org.kuali.kfs.module.tem.batch.TemProfileExportStep.java

@Override
public boolean execute(String jobName, Date jobRunDate) throws InterruptedException {
    List<TemProfile> profiles = temProfileService.getAllActiveTemProfile();

    //Accessing EXPORT_FILE_FORMAT sys param for export file extension
    LOG.info("Accessing EXPORT_FILE_FORMAT system parameter for file extension");
    String extension = getParameterService().getParameterValueAsString(TemProfileExportStep.class,
            TemConstants.TemProfileParameters.EXPORT_FILE_FORMAT);

    //Creating export file name
    String exportFile = fileDirectoryName + File.separator + fileName + "." + extension;

    //Initializing the output stream
    PrintStream OUTPUT_GLE_FILE_ps = null;
    try {//from  ww w  .ja v a 2s .c  o m
        OUTPUT_GLE_FILE_ps = new PrintStream(exportFile);
    } catch (FileNotFoundException ex) {
        throw new RuntimeException(ex.toString(), ex);
    }

    //Create file based on extension
    if (extension.equalsIgnoreCase("xml")) {
        try {
            OUTPUT_GLE_FILE_ps.printf("%s\n", generateXMLDoc(profiles));
        } catch (ParserConfigurationException ex) {
            throw new RuntimeException(ex.toString(), ex);
        } catch (TransformerException ex) {
            throw new RuntimeException(ex.toString(), ex);
        }
    } else {
        OUTPUT_GLE_FILE_ps.printf("%s\n",
                getDateTimeService().toDateTimeString(getDateTimeService().getCurrentDate()) + ","
                        + getParameterService().getParameterValueAsString(
                                KfsParameterConstants.FINANCIAL_SYSTEM_ALL.class,
                                KfsParameterConstants.INSTITUTION_NAME));
        for (TemProfile profile : profiles) {
            try {
                OUTPUT_GLE_FILE_ps.printf("%s\n", generateCSVEntry(profile));
            } catch (Exception e) {
                throw new RuntimeException(e.toString(), e);
            }
        }
    }

    OUTPUT_GLE_FILE_ps.close();

    return false;
}

From source file:com.nridge.core.base.std.StrUtl.java

/**
 * Given a string with a paragraph of words, a left margin pad size,
 * the width of the console or report page and an output stream, this
 * method will break the string into a formatted paragraph.
 *
 * @param aString A collection of words.
 * @param aLeftMargin Each line will be padded with this many spaces.
 * @param aLineWidth Identifies where characters should be wrapped.
 * @param aStream An output stream where each line will be written to.
 *///w  w  w  . j a  v  a2s  . c om
public static void wrapToStream(String aString, int aLeftMargin, int aLineWidth, PrintStream aStream) {
    String subStr;
    boolean isDone;
    StringBuilder strBuilder;
    int strPos, wrapPos, startPos, strLength;

    if ((StringUtils.isEmpty(aString)) || (aStream == null))
        return;

    strLength = aString.length();
    aLineWidth = Math.max(10, aLineWidth);
    aLeftMargin = Math.max(0, aLeftMargin);

    strPos = 0;
    isDone = false;

    while ((!isDone) && (strPos < strLength)) {
        subStr = aString.substring(strPos);

        strBuilder = new StringBuilder();
        for (int i = 0; i < aLeftMargin; i++)
            strBuilder.append(CHAR_SPACE);

        startPos = 0;
        while (subStr.charAt(startPos) == CHAR_SPACE)
            startPos++;

        strBuilder.append(subStr.substring(startPos));

        if (strBuilder.length() < aLineWidth) {
            aStream.printf("%s%n", strBuilder.toString());
            isDone = true;
        } else {
            wrapPos = lastWordIndex(strBuilder.toString(), aLineWidth);
            if (wrapPos == -1)
                break; // exception condition
            else {
                aStream.printf("%s%n", strBuilder.substring(0, wrapPos));
                strPos += wrapPos;
            }
        }
    }
}

From source file:org.apache.hadoop.mapred.gridmix.Gridmix.java

protected void printUsage(PrintStream out) {
    ToolRunner.printGenericCommandUsage(out);
    out.println("Usage: gridmix [-generate <MiB>] [-users URI] [-Dname=value ...] <iopath> <trace>");
    out.println("  e.g. gridmix -generate 100m foo -");
    out.println("Configuration parameters:");
    out.println("   General parameters:");
    out.printf("       %-48s : Output directory\n", GRIDMIX_OUT_DIR);
    out.printf("       %-48s : Submitting threads\n", GRIDMIX_SUB_THR);
    out.printf("       %-48s : Queued job desc\n", GRIDMIX_QUE_DEP);
    out.printf("       %-48s : User resolution class\n", GRIDMIX_USR_RSV);
    out.printf("       %-48s : Job types (%s)\n", JobCreator.GRIDMIX_JOB_TYPE, getJobTypes());
    out.println("   Parameters related to job submission:");
    out.printf("       %-48s : Default queue\n", GridmixJob.GRIDMIX_DEFAULT_QUEUE);
    out.printf("       %-48s : Enable/disable using queues in trace\n", GridmixJob.GRIDMIX_USE_QUEUE_IN_TRACE);
    out.printf("       %-48s : Job submission policy (%s)\n", GridmixJobSubmissionPolicy.JOB_SUBMISSION_POLICY,
            getSubmissionPolicies());//from  w  ww .ja v a  2s  . c o m
    out.println("   Parameters specific for LOADJOB:");
    out.printf("       %-48s : Key fraction of rec\n", AvgRecordFactory.GRIDMIX_KEY_FRC);
    out.println("   Parameters specific for SLEEPJOB:");
    out.printf("       %-48s : Whether to ignore reduce tasks\n", SleepJob.SLEEPJOB_MAPTASK_ONLY);
    out.printf("       %-48s : Number of fake locations for map tasks\n", JobCreator.SLEEPJOB_RANDOM_LOCATIONS);
    out.printf("       %-48s : Maximum map task runtime in mili-sec\n", SleepJob.GRIDMIX_SLEEP_MAX_MAP_TIME);
    out.printf("       %-48s : Maximum reduce task runtime in mili-sec (merge+reduce)\n",
            SleepJob.GRIDMIX_SLEEP_MAX_REDUCE_TIME);
    out.println("   Parameters specific for STRESS submission throttling policy:");
    out.printf("       %-48s : jobs vs task-tracker ratio\n", StressJobFactory.CONF_MAX_JOB_TRACKER_RATIO);
    out.printf("       %-48s : maps vs map-slot ratio\n", StressJobFactory.CONF_OVERLOAD_MAPTASK_MAPSLOT_RATIO);
    out.printf("       %-48s : reduces vs reduce-slot ratio\n",
            StressJobFactory.CONF_OVERLOAD_REDUCETASK_REDUCESLOT_RATIO);
    out.printf("       %-48s : map-slot share per job\n", StressJobFactory.CONF_MAX_MAPSLOT_SHARE_PER_JOB);
    out.printf("       %-48s : reduce-slot share per job\n",
            StressJobFactory.CONF_MAX_REDUCESLOT_SHARE_PER_JOB);
}

From source file:org.wso2.msf4j.internal.router.HttpServerTest.java

@Test(timeout = 5000)
public void testConnectionClose() throws Exception {
    URL url = baseURI.resolve("/test/v1/connectionClose").toURL();

    // Fire http request using raw socket so that we can verify the connection get closed by the server
    // after the response.
    Socket socket = createRawSocket(url);
    try {/*from  ww w  . ja va 2  s  .  c o  m*/
        PrintStream printer = new PrintStream(socket.getOutputStream(), false, "UTF-8");
        printer.printf("GET %s HTTP/1.1\r\n", url.getPath());
        printer.printf("Host: %s:%d\r\n", url.getHost(), url.getPort());
        printer.print("\r\n");
        printer.flush();

        // Just read everything from the response. Since the server will close the connection, the read loop should
        // end with an EOF. Otherwise there will be timeout of this test case
        String response = CharStreams.toString(new InputStreamReader(socket.getInputStream(), Charsets.UTF_8));
        Assert.assertTrue(response.startsWith("HTTP/1.1 200 OK"));
    } finally {
        socket.close();
    }
}

From source file:org.kuali.kfs.gl.service.impl.OriginEntryGroupServiceImpl.java

protected void buildBackupFileOutput(File[] doneFileList, PrintStream ps) {
    BufferedReader inputFileReader = null;

    for (File doneFile : doneFileList) {
        // get data file with done file
        File dataFile = getDataFile(doneFile);
        if (dataFile != null) {
            try {
                inputFileReader = new BufferedReader(new FileReader(dataFile.getPath()));
                String line = null;
                while ((line = inputFileReader.readLine()) != null) {
                    try {
                        ps.printf("%s\n", line);
                    } catch (Exception e) {
                        throw new IOException(e.toString());
                    }//from   ww  w. j ava 2s .  c  o m
                }
                inputFileReader.close();
                inputFileReader = null;

            } catch (Exception e) {
                throw new RuntimeException(e.toString());
            }

            doneFile.delete();
            postProcessDataFile(dataFile);

        }
    }
}

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

public void printNetworkStats(final InetAddress addr, PrintStream outs) {
    outs.printf("Mode: %s%n", probe.getOperationMode());
    Set<InetAddress> hosts = addr == null ? probe.getStreamDestinations() : new HashSet<InetAddress>() {
        {// w w w  . j a v a2  s  . co  m
            add(addr);
        }
    };
    if (hosts.size() == 0)
        outs.println("Not sending any streams.");
    for (InetAddress host : hosts) {
        try {
            List<String> files = probe.getFilesDestinedFor(host);
            if (files.size() > 0) {
                outs.printf("Streaming to: %s%n", host);
                for (String file : files)
                    outs.printf("   %s%n", file);
            } else {
                outs.printf(" Nothing streaming to %s%n", host);
            }
        } catch (IOException ex) {
            outs.printf("   Error retrieving file data for %s%n", host);
        }
    }

    hosts = addr == null ? probe.getStreamSources() : new HashSet<InetAddress>() {
        {
            add(addr);
        }
    };
    if (hosts.size() == 0)
        outs.println("Not receiving any streams.");
    for (InetAddress host : hosts) {
        try {
            List<String> files = probe.getIncomingFiles(host);
            if (files.size() > 0) {
                outs.printf("Streaming from: %s%n", host);
                for (String file : files)
                    outs.printf("   %s%n", file);
            } else {
                outs.printf(" Nothing streaming from %s%n", host);
            }
        } catch (IOException ex) {
            outs.printf("   Error retrieving file data for %s%n", host);
        }
    }

    MessagingServiceMBean ms = probe.getMsProxy();
    outs.printf("%-25s", "Pool Name");
    outs.printf("%10s", "Active");
    outs.printf("%10s", "Pending");
    outs.printf("%15s%n", "Completed");

    int pending;
    long completed;

    pending = 0;
    for (int n : ms.getCommandPendingTasks().values())
        pending += n;
    completed = 0;
    for (long n : ms.getCommandCompletedTasks().values())
        completed += n;
    outs.printf("%-25s%10s%10s%15s%n", "Commands", "n/a", pending, completed);

    pending = 0;
    for (int n : ms.getResponsePendingTasks().values())
        pending += n;
    completed = 0;
    for (long n : ms.getResponseCompletedTasks().values())
        completed += n;
    outs.printf("%-25s%10s%10s%15s%n", "Responses", "n/a", pending, completed);
}

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

private void setPower(PrintStream out, float power) {
    if (currentPower != power) {
        out.printf("7 101 %d\n", (int) (power * 100));
        currentPower = power;//  w  w  w  .  j a  v  a 2  s .c om
    }
}