Java Code Examples for java.io.PrintStream#format()

The following examples show how to use java.io.PrintStream#format() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: tmsi.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Print TMS_RTC_T 'rtc' to file 'fp'.
 *
 * @return number of printed characters.
 */
public static int tms_prt_vldelta_info(PrintStream fp, TMS_VLDELTA_INFO_T vld, int nr, int hdr) {

    int nc = 0; //*< number of printed characters
    int j; //*< general index

    if (fp == null) {
        return (nc);
    }
    if (hdr != 0) {
        fp = fp.format("# VL Delta Info\n");
        fp = fp.format("# %5s %6s %6s %6s %6s\n", "nr", "Config", "Length", "TransFS", "SampDiv");
    }
    fp = fp.format(" %6d %6d %6d %6d", nr, vld.Config, vld.Length, vld.TransFreqDiv);
    for (j = 0; j < vld.NrOfChannels; j++) {
        fp = fp.format(" %6d", vld.SampDiv[j]);
    }
    fp = fp.format("\n");
    return (nc);
}
 
Example 2
Source File: ClusterTool.java    From aeron with Apache License 2.0 6 votes vote down vote up
private static void printHelp(final PrintStream out)
{
    out.format(
        "Usage: <cluster-dir> <command> [options]%n" +
        "                   describe: prints out all descriptors in the file%n" +
        "                        pid: prints PID of cluster component%n" +
        "              recovery-plan: [service count] prints recovery plan of cluster component%n" +
        "              recording-log: prints recording log of cluster component%n" +
        "                     errors: prints Aeron and cluster component error logs%n" +
        "               list-members: print leader memberId, active members list, and passive members list%n" +
        "              remove-member: [memberId] requests removal of a member specified in memberId%n" +
        "             remove-passive: [memberId] requests removal of passive member specified in memberId%n" +
        "               backup-query: [delay] get time of next backup query or set time of next backup query%n" +
        " invalidate-latest-snapshot: Mark the latest snapshot as a invalid so previous is loaded%n" +
        "                   snapshot: Trigger a snapshot on the leader%n" +
        "                    suspend: Suspend reading from the ingress channel%n" +
        "                     resume: Resume reading from the ingress channel%n" +
        "                   shutdown: Do an orderly stop of the cluster with a snapshot%n" +
        "                      abort: Stop the cluster without a snapshot.%n");
    out.flush();
}
 
Example 3
Source File: StructClassFile.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void writeField(final Struct.Field field, final PrintStream out){
    if(field.type.type32 instanceof NBitfield){
        out.format("\t// Skipping bitfield '%1$s'\n", field.name);
        return;
    }
    String privName = field.name + "__";
    String offsetName = field.name.toUpperCase() + "_OFFSET";
    JType jtype = field.type.getJType();
    String retType = jtype.getJavaReturnTypeName();
    CoderDescriptor cdesc = jtype.getCoderDescriptor();
    out.println();
    out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName()
            + ".IS64 ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");

    out.println("\t//" + cdesc.getClass().toString());
    out.println("\tpublic " + retType + " " + getterName(field) + "(){");
    out.println(jtype.createPopAddr("getRuntime()", "this.raw.bufferPtr + " + offsetName));
    out.println(jtype.createReturn());
    out.println("\t}");
    out.println();
    out.println("\tpublic void " + setterName(field.name) + "(final " + retType + " " + privName + "){");
    out.println("\t\t" + cdesc.getPushAddrStatementFor("getRuntime()", "this.raw.bufferPtr + " + offsetName, privName));
    out.println("\t}");
}
 
Example 4
Source File: ClusterTool.java    From aeron with Apache License 2.0 6 votes vote down vote up
public static void nextBackupQuery(final PrintStream out, final File clusterDir, final long delayMs)
{
    if (markFileExists(clusterDir) || TIMEOUT_MS > 0)
    {
        try (ClusterMarkFile markFile = openMarkFile(clusterDir, System.out::println))
        {
            if (markFile.decoder().componentType() != ClusterComponentType.BACKUP)
            {
                out.println("not a cluster backup node");
            }
            else
            {
                final EpochClock epochClock = SystemEpochClock.INSTANCE;
                nextBackupQueryDeadlineMs(markFile, epochClock.time() + delayMs);
                out.format("%2$tF %1$tH:%1$tM:%1$tS setting next: %2$tF %2$tH:%2$tM:%2$tS%n",
                    new Date(),
                    new Date(nextBackupQueryDeadlineMs(markFile)));
            }
        }
    }
    else
    {
        out.println(ClusterMarkFile.FILENAME + " does not exist.");
    }
}
 
Example 5
Source File: JObjCClassClassFile.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override public void writeBeginning(final PrintStream out) {
    out.format(
            "\tpublic %1$s(%2$s runtime) {\n" +
            "\t\tsuper(runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
    out.format(
            "\tpublic %1$s(String name, %2$s runtime) {\n" +
            "\t\tsuper(name, runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
    out.format(
            "\tpublic %1$s(long ptr, %2$s runtime) {\n" +
            "\t\tsuper(ptr, runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
}
 
Example 6
Source File: AlignerCLI.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
private void outputs(
		PrintStream out,
		Term sourceTerm, 
		List<TranslationCandidate> candidates, 
		boolean explain) {
	
	for(int i = 0; i< candidates.size(); i++) {
		TranslationCandidate candidate = candidates.get(i);
		if(explain)
			out.format(OUTPUT_FORMAT_EXPL,
					i+1,
					sourceTerm.getPilot(),
					candidate.getTerm().getPilot(),
					candidate.getScore(),
					candidate.getMethod(),
					candidate.getExplanation().getText());
		else
			out.format(OUTPUT_FORMAT,
					i+1,
					sourceTerm.getPilot(),
					candidate.getTerm().getPilot(),
					candidate.getScore(),
					candidate.getMethod());
	}
}
 
Example 7
Source File: JObjCClassFile.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override public void writeBeginning(final PrintStream out) {
    out.format("\tpublic %1$s(final long objPtr, final %2$s runtime) {\n" +
            "\t\tsuper(objPtr, runtime);\n" +
            "\t}\n",
        className, JObjCRuntime.class.getCanonicalName());

    out.format("\tpublic %1$s(final %1$s obj, final %2$s runtime) {\n" +
            "\t\tsuper(obj, runtime);\n" +
            "\t}\n",
        className, JObjCRuntime.class.getCanonicalName());

    NativeObjectLifecycleManager nolm = nolmForClass.get(clazz.name);
    if(nolm != null)
        out.format("\t@Override\n"+
                "\tprotected %1$s getNativeObjectLifecycleManager() {\n" +
                "\t\treturn %2$s.INST;\n" +
                "\t}\n",
                NativeObjectLifecycleManager.class.getCanonicalName(), nolm.getClass().getCanonicalName());
}
 
Example 8
Source File: Blake2b.java    From AVM with MIT License 6 votes vote down vote up
public static void dumpBuffer(
        final PrintStream out,
        final String label,
        final byte[] b,
        final int offset,
        final int len) {
    if (label != null) {
        out.format("-- %s -- :\n", label);
    }
    out.format("{\n    ", label);
    for (int j = 0; j < len; ++j) {
        out.format("%02X", b[j + offset]);
        if (j + 1 < len) {
            if ((j + 1) % 8 == 0) {
                out.print("\n    ");
            } else {
                out.print(' ');
            }
        }
    }
    out.format("\n}\n");
}
 
Example 9
Source File: Inet6AddressSerializationTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static byte[] generateSerializedInet6AddressData(Inet6Address addr,
        PrintStream out, boolean outputToFile) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
        oos.writeObject(addr);
    }

    String ifname = getIfName(addr);
    byte[] ba = bos.toByteArray();
    if (out != null) {
        out.format("static final byte[] SerialData" + ifname + " = {\n");
        for (int i = 0; i < ba.length; i++) {
            out.format(" (byte)0x%02X", ba[i]);
            if (i != (ba.length - 1))
                out.format(",");
            if (((i + 1) % 6) == 0)
                out.format("\n");
        }
        out.format(" };\n \n");
    }
    if (outputToFile) {
        serializeInet6AddressToFile(addr);
    }
    return ba;
}
 
Example 10
Source File: ClusterTool.java    From aeron with Apache License 2.0 6 votes vote down vote up
public static void printNextBackupQuery(final PrintStream out, final File clusterDir)
{
    if (markFileExists(clusterDir) || TIMEOUT_MS > 0)
    {
        try (ClusterMarkFile markFile = openMarkFile(clusterDir, System.out::println))
        {
            if (markFile.decoder().componentType() != ClusterComponentType.BACKUP)
            {
                out.println("not a cluster backup node");
            }
            else
            {
                out.format("%2$tF %1$tH:%1$tM:%1$tS next: %2$tF %2$tH:%2$tM:%2$tS%n",
                    new Date(),
                    new Date(nextBackupQueryDeadlineMs(markFile)));
            }
        }
    }
    else
    {
        out.println(ClusterMarkFile.FILENAME + " does not exist.");
    }
}
 
Example 11
Source File: IntegerHistogram.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void print (PrintStream stream)
{
    stream.print("[\n");

    getDerivatives();

    for (Map.Entry<Integer, Integer> entry : entrySet()) {
        Integer key = entry.getKey();
        Double der = derivatives.get(key);
        stream.format(
                " %s: v:%d d:%s\n",
                key.toString(),
                entry.getValue(),
                (der != null) ? der.toString() : "");
    }

    stream.println("]");
}
 
Example 12
Source File: CliMain.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void printHelp(OptionParser parser, PrintStream stream) {
    try {
        stream.println("Bisq RPC Client");
        stream.println();
        stream.println("Usage: bisq-cli [options] <method> [params]");
        stream.println();
        parser.printHelpOn(stream);
        stream.println();
        stream.format("%-22s%-50s%s%n", "Method", "Params", "Description");
        stream.format("%-22s%-50s%s%n", "------", "------", "------------");
        stream.format("%-22s%-50s%s%n", "getversion", "", "Get server version");
        stream.format("%-22s%-50s%s%n", "getbalance", "", "Get server wallet balance");
        stream.format("%-22s%-50s%s%n", "getaddressbalance", "address", "Get server wallet address balance");
        stream.format("%-22s%-50s%s%n", "getfundingaddresses", "", "Get BTC funding addresses");
        stream.format("%-22s%-50s%s%n", "getoffers", "buy | sell, fiat currency code", "Get current offers");
        stream.format("%-22s%-50s%s%n", "createpaymentacct", "account name, account number, currency code", "Create PerfectMoney dummy account");
        stream.format("%-22s%-50s%s%n", "getpaymentaccts", "", "Get user payment accounts");
        stream.format("%-22s%-50s%s%n", "lockwallet", "", "Remove wallet password from memory, locking the wallet");
        stream.format("%-22s%-50s%s%n", "unlockwallet", "password timeout",
                "Store wallet password in memory for timeout seconds");
        stream.format("%-22s%-50s%s%n", "setwalletpassword", "password [newpassword]",
                "Encrypt wallet with password, or set new password on encrypted wallet");
        stream.println();
    } catch (IOException ex) {
        ex.printStackTrace(stream);
    }
}
 
Example 13
Source File: MoreKeysResources.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
private void dumpLocalesMap(final PrintStream out) {
    for (final StringResourceMap resMap : mResourcesMap.values()) {
        final Locale locale = resMap.mLocale;
        final String localeStr = LocaleUtils.getLocaleCode(locale);
        final String localeToDump = (locale == LocaleUtils.DEFAULT_LOCALE)
                ? String.format("\"%s\"", localeStr)
                : String.format("\"%s\"%s", localeStr, "       ".substring(localeStr.length()));
        out.format("        %s, %-12s /* %3d/%3d %s */\n",
                localeToDump, getArrayNameForLocale(locale) + ",",
                resMap.getResources().size(), resMap.getOutputArraySize(),
                LocaleUtils.getLocaleDisplayName(locale));
    }
}
 
Example 14
Source File: ViewSolutionSpace.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the secondary composite
 */
protected void showSecondaryComposite(int num, int max) {
    
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    ps.format(Resources.getMessage("LatticeView.7"), num, max); //$NON-NLS-1$
    label.setText(os.toString());
    
    this.layout.topControl = this.secondary;
    this.base.layout();
}
 
Example 15
Source File: CategoryClassFile.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override public void writeBeginning(final PrintStream out) {
    String targetCls = category.category.superClass.getFullPath();
    out.format("\tpublic %1$s(final %2$s obj, final %3$s runtime) {\n" +
            "\t\tsuper(obj, runtime);\n" +
            "\t}\n",
        className, targetCls, JObjCRuntime.class.getCanonicalName());
    super.writeBeginning(out);
}
 
Example 16
Source File: WriteAndPlotMS1Results.java    From act with GNU General Public License v3.0 5 votes vote down vote up
private void writeFeedMS1Values(List<Pair<Double, Double>> concentrationIntensity, OutputStream os)
    throws IOException {
  PrintStream out = new PrintStream(os);
  for (Pair<Double, Double> ci : concentrationIntensity) {
    out.format("%f\t%f\n", ci.getLeft(), ci.getRight());
  }
  out.flush();
}
 
Example 17
Source File: CategoryClassClassFile.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override public void writeBeginning(final PrintStream out) {
    out.format(
            "\t%1$s(%2$s runtime) {\n" +
            "\t\tsuper(\"%3$s\", runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName(), category.category.superClass.name);
}
 
Example 18
Source File: TimeWindowFixedBoundaryHistogram.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
void outputSummary(PrintStream printStream, double bucketScaling) {
    printStream.format("%14s %10s\n\n", "Bucket", "TotalCount");

    String bucketFormatString = "%14.1f %10d\n";

    for (int i = 0; i < buckets.length; i++) {
        printStream.format(Locale.US, bucketFormatString,
                buckets[i] / bucketScaling,
                currentHistogram().values.get(i));
    }

    printStream.write('\n');
}
 
Example 19
Source File: WindowsSecureContainerExecutor.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
protected void writeLocalWrapperScript(Path launchDst, Path pidFile, PrintStream pout) {
  pout.format("@call \"%s\"", launchDst);
}
 
Example 20
Source File: ApacheImagingSpeedAndMemoryTest.java    From commons-imaging with Apache License 2.0 4 votes vote down vote up
/**
 * Loads the input file multiple times, measuring the time and memory use
 * for each iteration.
 * @param fmt a valid PrintStream for formatting the output
 * @param name the path for the input image file to be tested
 */
private void performTest(final PrintStream fmt, final String name) {
    final File target = new File(name);
    double sumTime = 0;
    int n = 1;
    for (int i = 0; i < 10; i++) {
        try {
            ByteSourceFile byteSource = new ByteSourceFile(target);
            // This test code allows you to test cases where the
            // input is processed using Apache Imaging's
            // ByteSourceInputStream rather than the ByteSourceFile.
            // You might also want to experiment with ByteSourceArray.
            // FileInputStream fins = new FileInputStream(target);
            // BufferedInputStream bins = new BufferedInputStream(fins);
            // ByteSourceInputStream byteSource =
            // new ByteSourceInputStream(bins, target.getName());
            // ready the parser (you may modify this code block
            // to use your parser of choice)
            HashMap<String, Object> params = new HashMap<>();
            TiffImageParser tiffImageParser = new TiffImageParser();
            // load the file and record time needed to do so
            final long time0 = System.nanoTime();
            BufferedImage bImage = tiffImageParser.getBufferedImage(
                    byteSource, params);
            final long time1 = System.nanoTime();
            // tabulate results
            final double testTime = (time1 - time0) / 1000000.0;
            if (i > 1) {
                n = i - 1;
                sumTime += testTime;
            }
            final double avgTime = sumTime / n;
            // tabulate the memory results. Note that the
            // buffered image, the byte source, and the parser
            // are all still in scope. This approach is taken
            // to get some sense of peak memory use, but Java
            // may have already started collecting garbage,
            // so there are limits to the reliability of these
            // statistics
            final Runtime r = Runtime.getRuntime();
            final long freeMemory = r.freeMemory();
            final long totalMemory = r.totalMemory();
            final long usedMemory = totalMemory - freeMemory;
            if (i == 0) {
                // print header info
                fmt.format("%n");
                fmt.format("Processing file: %s%n", target.getName());
                fmt.format(" image size: %d by %d%n%n", bImage.getWidth(),
                        bImage.getHeight());
                fmt.format(" time to load image    --         memory%n");
                fmt.format(" time ms      avg ms   --    used mb   total mb%n");
            }
            fmt.format("%9.3f %9.3f    --  %9.3f %9.3f %n", testTime,
                    avgTime, usedMemory / (1024.0 * 1024.0), totalMemory
                            / (1024.0 * 1024.0));
            bImage = null;
            byteSource = null;
            params = null;
            tiffImageParser = null;
        } catch (final ImageReadException ire) {
            ire.printStackTrace();
            System.exit(-1);
        } catch (final IOException ioex) {
            ioex.printStackTrace();
            System.exit(-1);
        }
        try {
            // sleep between loop iterations allows time
            // for the JVM to clean up memory. The Netbeans IDE
            // doesn't "get" the fact that we're doing this operation
            // deliberately and is apt offer hints
            // suggesting that the code should be modified
            Runtime.getRuntime().gc();
            Thread.sleep(1000);
        } catch (final InterruptedException iex) {
            // this isn't fatal, but shouldn't happen
            iex.printStackTrace();
        }
    }
}