|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.Writer cs132.util.IndentPrinter
public final class IndentPrinter
Printer that manages indentation. Helps when pretty-printing a hierarchy. For example:
IndentPrinter p = new IndentPrinter(out, " "); p.println("Root 1"); p.indent(); p.println("Child 1"); p.println("Child 2"); p.dedent(); p.println("Root 2");
Yields:
Root 1 Child 1 Child 2 Root 2
This class never buffers any data, so you don't need to use flush()
to force anything out. Calling flush()
will just flush on the
underlying Writer.
Field Summary | |
---|---|
static String |
DefaultIndent
Two spaces. |
Fields inherited from class java.io.Writer |
---|
lock |
Constructor Summary | |
---|---|
IndentPrinter(Writer out)
Equivalent to: IndentPrinter(out, IndentPrinter.DefaultIndent). |
|
IndentPrinter(Writer out,
String indent)
Equivalent to: IndentPrinter(out, indent, ""). |
|
IndentPrinter(Writer out,
String indent,
String prefix)
Equivalent to: IndentPrinter(out, indent, prefix, true). |
|
IndentPrinter(Writer out,
String indent,
String prefix,
boolean freshLine)
|
Method Summary | |
---|---|
IndentPrinter |
append(char c)
|
IndentPrinter |
append(CharSequence v)
|
IndentPrinter |
append(CharSequence v,
int start,
int end)
|
void |
close()
Closes the underlying stream. |
void |
dedent()
Decrease the indentation level by one. |
void |
dedent(int numIndents)
Decrease the indentation level by 'numIndents' indentations. |
void |
flush()
Flushes the underlying stream. |
void |
indent()
Increase the indentation level by one. |
void |
indent(int numIndents)
Increase the indentation level by 'numIndents' indentations. |
void |
print(boolean v)
|
void |
print(char v)
|
void |
print(char[] v)
|
void |
print(CharSequence v)
|
void |
print(double v)
|
void |
print(float v)
|
void |
print(int v)
|
void |
print(long v)
|
void |
print(Object v)
|
void |
print(String v)
|
void |
println()
|
void |
println(boolean v)
|
void |
println(char v)
|
void |
println(char[] v)
|
void |
println(CharSequence v)
|
void |
println(double v)
|
void |
println(float v)
|
void |
println(int v)
|
void |
println(long v)
|
void |
println(Object v)
|
void |
println(String v)
|
void |
write(char c)
|
void |
write(char[] buf)
|
void |
write(char[] buf,
int off,
int len)
|
void |
write(String s)
|
void |
write(String s,
int off,
int len)
|
Methods inherited from class java.io.Writer |
---|
write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DefaultIndent
Constructor Detail |
---|
public IndentPrinter(Writer out, String indent, String prefix, boolean freshLine)
indent
- The string to add to the prefix for each additional indent
level.prefix
- The indentation to prefix to the beginning of each line.freshLine
- If we're starting on a "fresh" line, we need to add indentation
to the very first thing printed. If false, then we'll only start
adding indentation after the first 'println'.public IndentPrinter(Writer out, String indent, String prefix)
public IndentPrinter(Writer out, String indent)
public IndentPrinter(Writer out)
Method Detail |
---|
public void indent(int numIndents)
public void indent()
public void dedent(int numIndents)
public void dedent()
public void print(String v) throws IOException
IOException
public void print(char[] v) throws IOException
IOException
public void print(Object v) throws IOException
IOException
public void print(char v) throws IOException
IOException
public void print(int v) throws IOException
IOException
public void print(long v) throws IOException
IOException
public void print(double v) throws IOException
IOException
public void print(float v) throws IOException
IOException
public void print(boolean v) throws IOException
IOException
public void print(CharSequence v) throws IOException
IOException
public IndentPrinter append(CharSequence v) throws IOException
append
in interface Appendable
append
in class Writer
IOException
public IndentPrinter append(CharSequence v, int start, int end) throws IOException
append
in interface Appendable
append
in class Writer
IOException
public IndentPrinter append(char c) throws IOException
append
in interface Appendable
append
in class Writer
IOException
public void println(String v) throws IOException
IOException
public void println(char[] v) throws IOException
IOException
public void println(Object v) throws IOException
IOException
public void println(char v) throws IOException
IOException
public void println(int v) throws IOException
IOException
public void println(long v) throws IOException
IOException
public void println(double v) throws IOException
IOException
public void println(float v) throws IOException
IOException
public void println(boolean v) throws IOException
IOException
public void println(CharSequence v) throws IOException
IOException
public void println() throws IOException
IOException
public void write(char[] buf) throws IOException
write
in class Writer
IOException
public void write(char[] buf, int off, int len) throws IOException
write
in class Writer
IOException
public void write(char c) throws IOException
IOException
public void write(String s) throws IOException
write
in class Writer
IOException
public void write(String s, int off, int len) throws IOException
write
in class Writer
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class Writer
IOException
public void close() throws IOException
close
in interface Closeable
close
in class Writer
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |