Java Reference
In-Depth Information
/** Where the output goes */
PrintWriter out
;
/** If files present, format each, else format the standard input. */
public
public static
static
void
void
main
(
String
[]
av
)
throws
throws
IOException
{
iif
(
av
.
length
==
0
)
new
new
Fmt
(
System
.
in
).
format
();
else
else
for
(
String name
:
av
) {
new
new
Fmt
(
name
).
format
();
}
}
public
public
Fmt
(
BufferedReader inFile
,
PrintWriter outFile
) {
this
this
.
in
=
inFile
;
this
this
.
out
=
outFile
;
}
public
public
Fmt
(
PrintWriter out
) {
this
this
(
new
new
BufferedReader
(
new
new
InputStreamReader
(
System
.
in
)),
out
);
}
/** Construct a Formatter given an open Reader */
public
public
Fmt
(
BufferedReader file
)
throws
throws
IOException
{
this
this
(
file
,
new
new
PrintWriter
(
System
.
out
));
}
/** Construct a Formatter given a filename */
public
public
Fmt
(
String fname
)
throws
throws
IOException
{
this
this
(
new
new
BufferedReader
(
new
new
FileReader
(
fname
)));
}
/** Construct a Formatter given an open Stream */
public
public
Fmt
(
InputStream file
)
throws
throws
IOException
{
this
this
(
new
new
BufferedReader
(
new
new
InputStreamReader
(
file
)));
}
/** Format the File contained in a constructed Fmt object */
public
public
void
void
format
()
throws
throws
IOException
{
String line
;
StringBuilder outBuf
=
new
new
StringBuilder
();
while
while
((
line
=
in
.
readLine
()) !=
null
null
) {
iif
(
line
.
length
() ==
0
) {
// null line
out
.
println
(
outBuf
);
// end current line
out
.
println
();
// output blank line
outBuf
.
setLength
(
0
);
}
else
else
{