|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.myjavatools.lib.FormattedWriter
public class FormattedWriter
Constructor Summary | |
---|---|
FormattedWriter(java.io.OutputStream os,
java.lang.String format)
Creates a writer that formats its output according to the format specified |
|
FormattedWriter(java.io.OutputStream os,
java.lang.String head,
java.lang.String body,
java.lang.String tail)
Creates a writer that formats its output according to head, body and tail formats specified |
|
FormattedWriter(java.io.Writer writer,
java.lang.String format)
Creates a writer that formats its output according to the format specified |
|
FormattedWriter(java.io.Writer writer,
java.lang.String head,
java.lang.String body,
java.lang.String tail)
Creates a writer that formats its output according to head, body and tail formats specified |
Method Summary | |
---|---|
void |
close()
Writes the tail to formatted output and closes it |
void |
close(java.lang.Object[] args)
Writes the tail to formatted output and closes it |
java.text.MessageFormat |
getBody()
Gets body format string |
java.text.MessageFormat |
getHead()
Gets head format string |
java.text.MessageFormat |
getTail()
gets tail format string |
void |
open()
Opens formatted output, no arguments for head format |
void |
open(java.lang.Object arg)
Opens formatted output |
void |
open(java.lang.Object[] args)
Opens formatted output |
void |
write(java.lang.Object[] args)
Writes a body string to formatted output |
void |
write(java.lang.String s)
Writes an arbitrary string to (generally speaking) formatted output |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FormattedWriter(java.io.Writer writer, java.lang.String format)
writer
- the writer that outputs the formatted contentsformat
- head format string
Example
String format = "Copyright (c) {0} {1}\r\n\r\n" +
"{2}\r\n";
FileFormat ff = new FileFormat(new FileWriter("readme.txt"), format);
ff.write("George Rasputin", "" + new Date().getYear(), "This is a stub for future readme text");
This code will produce something like this:
Copyright (c) George Rasputin 2004
This is a stub for future readme text
FormattedWriter(Writer,String,String,String)
public FormattedWriter(java.io.Writer writer, java.lang.String head, java.lang.String body, java.lang.String tail)
writer
- the writer that outputs the formatted contentshead
- format string for the file headbody
- format string for (repeating) entries of the file bodytail
- format strings for the file tail
Example
String head = "/*\r\n Resource Data for package {0} in project {1}\r\n/*\r\n" +
"class ResourceData {\r\n";
String body = " public String {0} = \"{1}\";\r\n";
String tail = "}\r\n";
FileFormat ff = new FileFormat(new FileWriter("resource.java", head, body, tail);
ff.open(packageName, "My Cool Project");
Properties p = ...;
for (Enumeration i = p.keys(); i.hasMoreElements();) {
String key = i.nextElement().toString();
ff.write(new String[] {key, p.getProperty(key, "undef"});
}
ff.close();
This code will produce something like this:
/*
Resource Data for package com.my.package in project My Cool Project
*/
class ResourceData {
String dialogTitle = "Romeo vs Juliet";
String label1 = "One of unmentionable major copyrighted labels";
String size = "100x200";
}
public FormattedWriter(java.io.OutputStream os, java.lang.String format)
os
- output stream that outputs the formatted contentsformat
- head format stringFormattedWriter(Writer,String)
public FormattedWriter(java.io.OutputStream os, java.lang.String head, java.lang.String body, java.lang.String tail)
os
- output stream that outputs the formatted contentshead
- format string for the file headbody
- format string for (repeating) entries of the file bodytail
- format strings for the file tailFormattedWriter(Writer,String,String,String)
Method Detail |
---|
public java.text.MessageFormat getHead()
public java.text.MessageFormat getBody()
public java.text.MessageFormat getTail()
public void open(java.lang.Object[] args) throws java.io.IOException
args
- arguments for the head format
java.io.IOException
- if write operation failespublic void open(java.lang.Object arg) throws java.io.IOException
arg
- the only argiment for the head format
java.io.IOException
- if write operation failspublic void open() throws java.io.IOException
java.io.IOException
public void write(java.lang.Object[] args) throws java.io.IOException
args
- arguments for body format
java.io.IOException
- if write operation fails
Note. If body format is missing (then there is only head format),
then head format is applied to the arguments, the result of formatting is
written to the output, and the writer is closed.public void write(java.lang.String s) throws java.io.IOException
s
- the string to output
java.io.IOException
- if write operation fails
This skips any formatting; the string is just sent to output "as is".public void close(java.lang.Object[] args) throws java.io.IOException
args
- arguments for tail format
java.io.IOException
- if write operation fails
Note. if there is no tail format, the output just closes.public void close() throws java.io.IOException
java.io.IOException
- if write operation fails
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |