| java.lang.Object java.util.Formatter
Formatter | final public class Formatter implements Closeable,Flushable(Code) | | Formatter provides the method to give out formatted string just like the
printf-style. Layout,alignment and other format flags are provided to format
numeric,string and date/time as well as locale-specified formats applied.
Besides primitive types, formatter also support some java object types such
as BigInteger,BigDecimal and Calendar. Customized formatting is provided
through the Formattable interface.
The class is not multi-threaded safe. The responsibility to maintain thread
safety is the user's job.
since: 1.5 |
Inner Class :public enum BigDecimalLayoutForm | |
Constructor Summary | |
public | Formatter() Constructs a formatter. | public | Formatter(Appendable a) Constructs a formatter of which the output is denoted.
The locale for the formatter is the default locale of the JVM.
Parameters: a - The output of the formatter. | public | Formatter(Locale l) Constructs a formatter of which the locale is denoted.
The output destination is a StringBuilder which can be achieved by
invoking the out method and whose contents can be attained by calling the
toString method.
Parameters: l - The locale of the formatter. | public | Formatter(Appendable a, Locale l) Constructs a formatter of which the output and locale is denoted.
Parameters: a - The output of the formatter. | public | Formatter(String fileName) Constructs a formatter of which the filename is denoted.
The charset of the formatter is the default charset of JVM.
The locale for the formatter is the default locale of the JVM.
Parameters: fileName - The filename of the file that is used as the outputdestination for the formatter. | public | Formatter(String fileName, String csn) Constructs a formatter of which the filename and charset is denoted.
The locale for the formatter is the default locale of the JVM.
Parameters: fileName - The filename of the file that is used as the outputdestination for the formatter. | public | Formatter(String fileName, String csn, Locale l) Constructs a formatter of which the filename, charset and locale is
denoted.
Parameters: fileName - The filename of the file that is used as the outputdestination for the formatter. | public | Formatter(File file) Constructs a formatter of which the file is denoted.
The charset of the formatter is the default charset of JVM.
The locale for the formatter is the default locale of the JVM.
Parameters: file - The file that is used as the output destination for theformatter. | public | Formatter(File file, String csn) Constructs a formatter of which the file and charset is denoted.
The locale for the formatter is the default locale of the JVM.
Parameters: file - The file of the file that is used as the output destinationfor the formatter. | public | Formatter(File file, String csn, Locale l) Constructs a formatter of which the file, charset and locale is denoted.
Parameters: file - file that is used as the output destination for the formatter.The file will be truncated to zero size if the file exists, orelse a new file will be created. | public | Formatter(OutputStream os) Constructs a formatter of which the output destination is specified. | public | Formatter(OutputStream os, String csn) Constructs a formatter of which the output destination and the charset is
specified. | public | Formatter(OutputStream os, String csn, Locale l) Constructs a formatter of which the output destination, the charset and
the locale is specified.
Parameters: os - The stream used as the destination of the formatter. Parameters: csn - The name of the charset for the formatter. Parameters: l - The locale of the formatter. | public | Formatter(PrintStream ps) Constructs a formatter of which the output destination is specified.
The charset of the formatter is the default charset of JVM.
The locale for the formatter is the default locale of the JVM.
Parameters: ps - The print stream used as destination of the formatter. |
Method Summary | |
public void | close() Closes the formatter. | public void | flush() Flushes the formatter. | public Formatter | format(String format, Object... args) Writes a formatted string to the output destination of the formatter.
Parameters: format - A format string. Parameters: args - The arguments list used in the format() method. | public Formatter | format(Locale l, String format, Object... args) Writes a formatted string to the output destination of the formatter.
Parameters: l - The locale used in the method. | public IOException | ioException() Returns the last IOException thrown out by the formatter's output
destination. | public Locale | locale() Returns the locale of the formatter. | public Appendable | out() Returns the output destination of the formatter. | public String | toString() Returns the content by calling the toString() method of the output
destination. |
Formatter | public Formatter()(Code) | | Constructs a formatter.
The output is a StringBuilder which can be achieved by invoking the out
method and whose contents can be attained by calling the toString method.
The locale for the formatter is the default locale of the JVM.
|
Formatter | public Formatter(Appendable a)(Code) | | Constructs a formatter of which the output is denoted.
The locale for the formatter is the default locale of the JVM.
Parameters: a - The output of the formatter. If a is null, then aStringBuilder will be used. |
Formatter | public Formatter(Locale l)(Code) | | Constructs a formatter of which the locale is denoted.
The output destination is a StringBuilder which can be achieved by
invoking the out method and whose contents can be attained by calling the
toString method.
Parameters: l - The locale of the formatter. If l is null, then nolocalization will be used. |
Formatter | public Formatter(Appendable a, Locale l)(Code) | | Constructs a formatter of which the output and locale is denoted.
Parameters: a - The output of the formatter. If a is null, then aStringBuilder will be used. Parameters: l - The locale of the formatter. If l is null, then nolocalization will be used. |
Formatter | public Formatter(String fileName) throws FileNotFoundException(Code) | | Constructs a formatter of which the filename is denoted.
The charset of the formatter is the default charset of JVM.
The locale for the formatter is the default locale of the JVM.
Parameters: fileName - The filename of the file that is used as the outputdestination for the formatter. The file will be truncated tozero size if the file exists, or else a new file will becreated. The output of the formatter is buffered. throws: FileNotFoundException - If the filename does not denote a normal and writable file,or a new file cannot be created or any error rises whenopening or creating the file. throws: SecurityException - If there is a security manager and it denies writing to thefile in checkWrite(file.getPath()). |
Formatter | public Formatter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException(Code) | | Constructs a formatter of which the filename and charset is denoted.
The locale for the formatter is the default locale of the JVM.
Parameters: fileName - The filename of the file that is used as the outputdestination for the formatter. The file will be truncated tozero size if the file exists, or else a new file will becreated. The output of the formatter is buffered. Parameters: csn - The name of the charset for the formatter. throws: FileNotFoundException - If the filename does not denote a normal and writable file,or a new file cannot be created or any error rises whenopening or creating the file. throws: SecurityException - If there is a security manager and it denies writing to thefile in checkWrite(file.getPath()). throws: UnsupportedEncodingException - If the charset with the specified name is not supported. |
Formatter | public Formatter(String fileName, String csn, Locale l) throws FileNotFoundException, UnsupportedEncodingException(Code) | | Constructs a formatter of which the filename, charset and locale is
denoted.
Parameters: fileName - The filename of the file that is used as the outputdestination for the formatter. The file will be truncated tozero size if the file exists, or else a new file will becreated. The output of the formatter is buffered. Parameters: csn - The name of the charset for the formatter. Parameters: l - The locale of the formatter. If l is null, then nolocalization will be used. throws: FileNotFoundException - If the filename does not denote a normal and writable file,or a new file cannot be created or any error rises whenopening or creating the file. throws: SecurityException - If there is a security manager and it denies writing to thefile in checkWrite(file.getPath()). throws: UnsupportedEncodingException - If the charset with the specified name is not supported. |
Formatter | public Formatter(File file) throws FileNotFoundException(Code) | | Constructs a formatter of which the file is denoted.
The charset of the formatter is the default charset of JVM.
The locale for the formatter is the default locale of the JVM.
Parameters: file - The file that is used as the output destination for theformatter. The file will be truncated to zero size if the fileexists, or else a new file will be created. The output of theformatter is buffered. throws: FileNotFoundException - If the file does not denote a normal and writable file, or anew file cannot be created or any error rises when opening orcreating the file. throws: SecurityException - If there is a security manager and it denies writing to thefile in checkWrite(file.getPath()). |
Formatter | public Formatter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException(Code) | | Constructs a formatter of which the file and charset is denoted.
The locale for the formatter is the default locale of the JVM.
Parameters: file - The file of the file that is used as the output destinationfor the formatter. The file will be truncated to zero size ifthe file exists, or else a new file will be created. Theoutput of the formatter is buffered. Parameters: csn - The name of the charset for the formatter. throws: FileNotFoundException - If the file does not denote a normal and writable file, or anew file cannot be created or any error rises when opening orcreating the file. throws: SecurityException - If there is a security manager and it denies writing to thefile in checkWrite(file.getPath()). throws: UnsupportedEncodingException - If the charset with the specified name is not supported. |
Formatter | public Formatter(File file, String csn, Locale l) throws FileNotFoundException, UnsupportedEncodingException(Code) | | Constructs a formatter of which the file, charset and locale is denoted.
Parameters: file - file that is used as the output destination for the formatter.The file will be truncated to zero size if the file exists, orelse a new file will be created. The output of the formatteris buffered. Parameters: csn - The name of the charset for the formatter. Parameters: l - The locale of the formatter. If l is null, then nolocalization will be used. throws: FileNotFoundException - If the file does not denote a normal and writable file, or anew file cannot be created or any error rises when opening orcreating the file. throws: SecurityException - If there is a security manager and it denies writing to thefile in checkWrite(file.getPath()). throws: UnsupportedEncodingException - If the charset with the specified name is not supported. |
Formatter | public Formatter(OutputStream os)(Code) | | Constructs a formatter of which the output destination is specified.
The charset of the formatter is the default charset of JVM.
The locale for the formatter is the default locale of the JVM.
Parameters: os - The stream used as the destination of the formatter. |
Formatter | public Formatter(OutputStream os, String csn) throws UnsupportedEncodingException(Code) | | Constructs a formatter of which the output destination and the charset is
specified.
The locale for the formatter is the default locale of the JVM.
Parameters: os - The stream used as the destination of the formatter. Parameters: csn - The name of the charset for the formatter. throws: UnsupportedEncodingException - If the charset with the specified name is not supported. |
Formatter | public Formatter(OutputStream os, String csn, Locale l) throws UnsupportedEncodingException(Code) | | Constructs a formatter of which the output destination, the charset and
the locale is specified.
Parameters: os - The stream used as the destination of the formatter. Parameters: csn - The name of the charset for the formatter. Parameters: l - The locale of the formatter. If l is null, then nolocalization will be used. throws: UnsupportedEncodingException - If the charset with the specified name is not supported. |
Formatter | public Formatter(PrintStream ps)(Code) | | Constructs a formatter of which the output destination is specified.
The charset of the formatter is the default charset of JVM.
The locale for the formatter is the default locale of the JVM.
Parameters: ps - The print stream used as destination of the formatter. If psis null, then NullPointerExcepiton will be thrown out. |
close | public void close()(Code) | | Closes the formatter. If the output destination is
Closeable ,
then the method close() will be called on that destination.
If the formatter has been closed, then calling the close will have no
effect.
Any method but the ioException() that is called after the formatter has
been closed will raise a FormatterClosedException.
|
flush | public void flush()(Code) | | Flushes the formatter. If the output destination is
Flushable ,
then the method flush() will be called on that destination.
throws: FormatterClosedException - If the formatter has been closed. |
format | public Formatter format(String format, Object... args)(Code) | | Writes a formatted string to the output destination of the formatter.
Parameters: format - A format string. Parameters: args - The arguments list used in the format() method. If there aremore arguments than those specified by the format string, thenthe additional arguments are ignored. This formatter. throws: IllegalFormatException - If the format string is illegal or incompatible with thearguments or the arguments are less than those required bythe format string or any other illegal situation. throws: FormatterClosedException - If the formatter has been closed. |
format | public Formatter format(Locale l, String format, Object... args)(Code) | | Writes a formatted string to the output destination of the formatter.
Parameters: l - The locale used in the method. If locale is null, then nolocalization will be applied. This parameter does notinfluence the locale specified during construction. Parameters: format - A format string. Parameters: args - The arguments list used in the format() method. If there aremore arguments than those specified by the format string, thenthe additional arguments are ignored. This formatter. throws: IllegalFormatException - If the format string is illegal or incompatible with thearguments or the arguments are less than those required bythe format string or any other illegal situation. throws: FormatterClosedException - If the formatter has been closed. |
ioException | public IOException ioException()(Code) | | Returns the last IOException thrown out by the formatter's output
destination. If the append() method of the destination will not throw
IOException, the ioException() method will always return null.
The last IOException thrown out by the formatter's outputdestination. |
locale | public Locale locale()(Code) | | Returns the locale of the formatter.
The locale for the formatter and null for no locale. throws: FormatterClosedException - If the formatter has been closed. |
toString | public String toString()(Code) | | Returns the content by calling the toString() method of the output
destination.
The content by calling the toString() method of the outputdestination. throws: FormatterClosedException - If the formatter has been closed. |
|
|