Sharkysoft home

lava.clib
Class Stdio

java.lang.Object
  |
  +--lava.clib.Stdio

public class Stdio
extends java.lang.Object

Ports of stdio functions.

Details: Stdio is port of the famous stdio library from the C programming language. By emulating many of the C language's stdio library functions, this class lets die-hard C programmers write Java code without completely converting to the Java API. Rather than wasting valuable time figuring out how to perform the Java equivalent of tasks that are easy in C, the programmer can simply use the methods in this class instead.

printf functions

The printf functions in the class are by far the most important reason for this class' existance, and are the core component of Printf for Java (go figure). If you learn to use printf well, it will make text formatting in Java extremely easy. Although the printf, sprintf, and fprintf methods included in this class are geared for programmers who are already familiar with the printf function in C, the printf interfaces are simple enough for anyone to use. Nevertheless, every attempt has been made to ensure that these functions work exactly as experienced C programmers would expect them to.

The printf methods format text according to the supplied format string, which is represented as a sequence of literal substrings and format specifiers. Literal substrings are echoed in the output, verbatim, but format specifiers are expanded with text-formatted representations of additional variables that are provided.

A format string can contain any number of expandable format specifiers. Thus, a variable number of additional parameters are required to complete the substitution. Since Java does not support variable length argument lists, additional parameters must be passed in an Object array.

For detailed information on all the cool things you can do with Printf for Java, see Printf for Java.

All of the printf methods included in this class format data in exactly the same way. However, what is done with the formatted result depends on the specific variation of printf that is being used. Some of the printf methods, for example, output directly to System.out, while others may store the output in a file or string.

Each of the printf variants accept format strings as either String objects or lava.clib.stdio.PrintfFormatString objects. Use of the latter type results in more efficient execution, but is slightly more complex to implement. For more details, see lava.clib.stdio.PrintfFormatString.

scanf functions

The scanf functions are not available in this release of Lava -- but they are planned for future releases.

Since:
before 1998.02.19
Version:
1999.10.11
See Also:
Printf, PrintfFormatString, Va_list

Method Summary
static int fprintf(java.io.PrintStream printstream, PrintfFormatString format, java.lang.Object[] args)
          Formats data and sends the result to a PrintStream.
static int fprintf(java.io.PrintStream printstream, java.lang.String format)
           
static int fprintf(java.io.PrintStream printstream, java.lang.String format, java.lang.Object[] args)
          Formats data and sends the result to a PrintStream.
static int fprintf(java.io.PrintStream printstream, java.lang.String format, Va_list args)
          Formats data and sends the result to a PrintStream.
static int fprintf(java.io.PrintWriter printwriter, PrintfFormatString format, java.lang.Object[] args)
          Formats data and sends the result to a PrintWriter.
static int fprintf(java.io.PrintWriter printwriter, java.lang.String format)
           
static int fprintf(java.io.PrintWriter printwriter, java.lang.String format, java.lang.Object[] args)
          Formats data and sends the result to a PrintWriter.
static int fprintf(java.io.PrintWriter printwriter, java.lang.String format, Va_list args)
          Formats data and sends the result to a PrintWriter.
static int fprintf(java.io.Writer writer, PrintfFormatString format, java.lang.Object[] args)
          Formats data and sends the result to a Writer.
static int fprintf(java.io.Writer writer, java.lang.String format)
           
static int fprintf(java.io.Writer writer, java.lang.String format, java.lang.Object[] args)
          Formats data and sends the result to a Writer.
static int fprintf(java.io.Writer writer, java.lang.String format, Va_list args)
          Formats data and sends the result to a Writer.
static int printf(PrintfFormatString format, java.lang.Object[] args)
          Formats data and writes the result to System.out.
static int printf(java.lang.String format)
           
static int printf(java.lang.String format, java.lang.Object[] args)
          Formats data and writes the result to System.out.
static int printf(java.lang.String format, Va_list args)
          Formats data and writes the result to System.out.
static int sprintf(java.lang.StringBuffer buff, PrintfFormatString format, java.lang.Object[] args)
          Formats data and stores the result in a StringBuffer.
static int sprintf(java.lang.StringBuffer buff, java.lang.String format)
           
static int sprintf(java.lang.StringBuffer buff, java.lang.String format, java.lang.Object[] args)
          Formats data and stores the result in a StringBuffer.
static int sprintf(java.lang.StringBuffer buff, java.lang.String format, Va_list args)
          Formats data and stores the result in a StringBuffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

printf

public static final int printf(java.lang.String format,
                               Va_list args)
Formats data and writes the result to System.out. See the discussion at the head of this document.
Parameters:
format - the format string
args - data to be formatted
Returns:
the number of characters printed
Throws:
PrintfFormatException - if the format string is invalid
See Also:
PrintfFormatString, Va_list

printf

public static final int printf(java.lang.String format,
                               java.lang.Object[] args)
Formats data and writes the result to System.out. See the discussion at the head of this document.
Parameters:
format - the format string
args - data to be formatted
Returns:
the number of characters printed
Throws:
PrintfFormatException - if the format string is invalid
See Also:
PrintfFormatString, Va_list

printf

public static final int printf(java.lang.String format)

printf

public static final int printf(PrintfFormatString format,
                               java.lang.Object[] args)
Formats data and writes the result to System.out. See the discussion at the head of this document.
Parameters:
format - the format string
args - data to be formatted
Returns:
the number of characters printed
Throws:
PrintfFormatException - if the format string is invalid
See Also:
Va_list

sprintf

public static final int sprintf(java.lang.StringBuffer buff,
                                java.lang.String format,
                                Va_list args)
Formats data and stores the result in a StringBuffer. The previous contents of the StringBuffer, if any, are overwritten. See the discussion at the head of this document.
Parameters:
buff - the destination buffer
format - the format string
args - data to be formatted
Returns:
the number of characters printed
Throws:
PrintfFormatException - if the format string is invalid
See Also:
PrintfFormatString, Va_list

sprintf

public static final int sprintf(java.lang.StringBuffer buff,
                                java.lang.String format,
                                java.lang.Object[] args)
Formats data and stores the result in a StringBuffer. The previous contents of the StringBuffer, if any, are overwritten. See the discussion at the head of this document.
Parameters:
buff - the destination buffer
format - the format string
args - data to be formatted
Returns:
the number of characters printed
Throws:
PrintfFormatException - if the format string is invalid
See Also:
PrintfFormatString, Va_list

sprintf

public static final int sprintf(java.lang.StringBuffer buff,
                                java.lang.String format)

sprintf

public static final int sprintf(java.lang.StringBuffer buff,
                                PrintfFormatString format,
                                java.lang.Object[] args)
Formats data and stores the result in a StringBuffer. The previous contents of the StringBuffer, if any, are overwritten. See the discussion at the head of this document.
Parameters:
buff - the destination buffer
format - the format string
args - data to be formatted
Returns:
the number of characters printed
Throws:
PrintfFormatException - if the format string is invalid
See Also:
Va_list

fprintf

public static final int fprintf(java.io.Writer writer,
                                java.lang.String format,
                                Va_list args)
                         throws java.io.IOException
Formats data and sends the result to a Writer. See the discussion at the head of this document.
Parameters:
writer - the destination stream
format - the format string
args - data to be formatted
Returns:
the number of characters output
Throws:
PrintfFormatException - if the format string is invalid
See Also:
PrintfFormatString, Va_list

fprintf

public static final int fprintf(java.io.Writer writer,
                                java.lang.String format,
                                java.lang.Object[] args)
                         throws java.io.IOException
Formats data and sends the result to a Writer. See the discussion at the head of this document.
Parameters:
writer - the destination stream
format - the format string
args - data to be formatted
Returns:
the number of characters output
Throws:
PrintfFormatException - if the format string is invalid
See Also:
PrintfFormatString, Va_list

fprintf

public static final int fprintf(java.io.Writer writer,
                                java.lang.String format)
                         throws java.io.IOException

fprintf

public static final int fprintf(java.io.Writer writer,
                                PrintfFormatString format,
                                java.lang.Object[] args)
                         throws java.io.IOException
Formats data and sends the result to a Writer. See the discussion at the head of this document.
Parameters:
writer - the destination stream
format - the format string
args - data to be formatted
Returns:
the number of characters output
Throws:
PrintfFormatException - if the format string is invalid
See Also:
Va_list

fprintf

public static final int fprintf(java.io.PrintStream printstream,
                                java.lang.String format,
                                Va_list args)
Formats data and sends the result to a PrintStream. See the discussion at the head of this document.
Parameters:
printstream - the destination stream
format - the format string
args - data to be formatted
Returns:
the number of characters output
Throws:
PrintfFormatException - if the format string is invalid
See Also:
PrintfFormatString, Va_list

fprintf

public static final int fprintf(java.io.PrintStream printstream,
                                java.lang.String format,
                                java.lang.Object[] args)
Formats data and sends the result to a PrintStream. See the discussion at the head of this document.
Parameters:
printstream - the destination stream
format - the format string
args - data to be formatted
Returns:
the number of characters output
Throws:
PrintfFormatException - if the format string is invalid
See Also:
PrintfFormatString, Va_list

fprintf

public static final int fprintf(java.io.PrintStream printstream,
                                java.lang.String format)

fprintf

public static final int fprintf(java.io.PrintStream printstream,
                                PrintfFormatString format,
                                java.lang.Object[] args)
Formats data and sends the result to a PrintStream. See the discussion at the head of this document.
Parameters:
printstream - the destination stream
format - the format string
args - data to be formatted
Returns:
the number of characters output
Throws:
PrintfFormatException - if the format string is invalid
See Also:
Va_list

fprintf

public static final int fprintf(java.io.PrintWriter printwriter,
                                java.lang.String format,
                                Va_list args)
Formats data and sends the result to a PrintWriter. See the discussion at the head of this document.
Parameters:
printwriter - the destination stream
format - the format string
args - data to be formatted
Returns:
the number of characters output
Throws:
PrintfFormatException - if the format string is invalid
Since:
1999.10.11
See Also:
PrintfFormatString, Va_list

fprintf

public static final int fprintf(java.io.PrintWriter printwriter,
                                java.lang.String format,
                                java.lang.Object[] args)
Formats data and sends the result to a PrintWriter. See the discussion at the head of this document.
Parameters:
printwriter - the destination stream
format - the format string
args - data to be formatted
Returns:
the number of characters output
Throws:
PrintfFormatException - if the format string is invalid
Since:
1999.10.11
See Also:
PrintfFormatString, Va_list

fprintf

public static final int fprintf(java.io.PrintWriter printwriter,
                                java.lang.String format)

fprintf

public static final int fprintf(java.io.PrintWriter printwriter,
                                PrintfFormatString format,
                                java.lang.Object[] args)
Formats data and sends the result to a PrintWriter. See the discussion at the head of this document.
Parameters:
printwriter - the destination stream
format - the format string
args - data to be formatted
Returns:
the number of characters output
Throws:
PrintfFormatException - if the format string is invalid
Since:
1999.10.11
See Also:
Va_list

Sharkysoft home