Example #1
0
 /**
  * Writes formatted output values to the current output destination. This method has the same
  * function as System.out.printf(); the details of formatted output are not discussed here. The
  * first parameter is a string that describes the format of the output. There can be any number of
  * additional parameters; these specify the values to be output and can be of any type. This
  * method will throw an IllegalArgumentException if the format string is null or if the format
  * string is illegal for the values that are being output.
  */
 public static void putf(String format, Object... items) {
   if (format == null)
     throw new IllegalArgumentException("Null format string in TextIO.putf() method.");
   try {
     out.printf(format, items);
   } catch (IllegalFormatException e) {
     throw new IllegalArgumentException("Illegal format string in TextIO.putf() method.");
   }
   out.flush();
   if (out.checkError()) outputError("Error while writing output.");
 }
Example #2
0
 /** This is equivalent to put(x,minChars), followed by an end-of-line. */
 public static void putln(Object x, int minChars) {
   put(x, minChars);
   out.println();
   out.flush();
   if (out.checkError()) outputError("Error while writing output.");
 }
Example #3
0
 /** Write an end-of-line character to the current output destination. */
 public static void putln() {
   out.println();
   out.flush();
   if (out.checkError()) outputError("Error while writing output.");
 }
Example #4
0
 /**
  * Write a single value to the current output destination, using the default format and outputting
  * at least minChars characters (with extra spaces added before the output value if necessary).
  * This method will handle any type of parameter, even one whose type is one of the primitive
  * types.
  *
  * @param x The value to be output, which can be of any type.
  * @param minChars The minimum number of characters to use for the output. If x requires fewer
  *     then this number of characters, then extra spaces are added to the front of x to bring the
  *     total up to minChars. If minChars is less than or equal to zero, then x will be printed in
  *     the minumum number of spaces possible.
  */
 public static void put(Object x, int minChars) {
   if (minChars <= 0) out.print(x);
   else out.printf("%" + minChars + "s", x);
   out.flush();
   if (out.checkError()) outputError("Error while writing output.");
 }