Class Overview
A BufferedWriter that supports automatic indentation of lines of
text written to the underlying Writer.
Methods are provided for compact/convenient indenting in and out,
writing text, and writing lines of text in various combinations.
WARNING: The contents of this source file are not part of any
supported API. Code that depends on them does so at its own risk:
they are subject to change or removal without notice.
Summary
Public Constructors |
|
IndentingWriter(Writer out)
Creates a new IndentingWriter that writes indented text to the
given Writer.
|
|
IndentingWriter(Writer out, int indentStep)
Creates a new IndentingWriter that writes indented text to the
given Writer and uses the supplied indent step.
|
|
IndentingWriter(Writer out, int indentStep, int tabSize)
Creates a new IndentingWriter that writes indented text to the
given Writer and uses the supplied indent step and tab size.
|
Public Methods |
void
|
newLine()
Writes a line separator.
|
void
|
p(String s)
Writes string.
|
void
|
p(Object o)
Writes object.
|
void
|
pI()
Indents in.
|
void
|
pO()
Indents out.
|
void
|
pO(String s)
Indents out; writes string.
|
void
|
pO(Object o)
Indents out; writes object.
|
void
|
pOln(Object o)
Indents out; writes object; ends current line.
|
void
|
pOln(String s)
Indents out; writes string; ends current line.
|
void
|
pOlnI(String s)
Indents out; writes string; ends current line; indents in.
|
void
|
pOlnI(Object o)
Indents out; writes object; ends current line; indents in.
|
void
|
pln(String s)
Writes string; ends current line.
|
void
|
pln()
Ends current line.
|
void
|
pln(Object o)
Writes object; ends current line.
|
void
|
plnI(Object o)
Writes object; ends current line; indents in.
|
void
|
plnI(String s)
Writes string; ends current line; indents in.
|
void
|
write(char[] cbuf, int off, int len)
Writes a portion of an array of characters.
|
void
|
write(int c)
Writes a single character.
|
void
|
write(String s, int off, int len)
Writes a portion of a String.
|
Protected Methods |
void
|
checkWrite()
Checks if an indent needs to be written before writing the next
character.
|
void
|
indentIn()
Increases the current indent by the indent step.
|
void
|
indentOut()
Decreases the current indent by the indent step.
|
[Expand]
Inherited Methods |
From class
java.io.BufferedWriter
void
|
close()
Closes the stream, flushing it first.
|
void
|
flush()
Flushes the stream.
|
void
|
newLine()
Writes a line separator.
|
void
|
write(char[] cbuf, int off, int len)
Writes a portion of an array of characters.
|
void
|
write(String s, int off, int len)
Writes a portion of a String.
|
void
|
write(int c)
Writes a single character.
|
|
From class
java.io.Writer
Writer
|
append(CharSequence csq)
Appends the specified character sequence to this writer.
|
Writer
|
append(CharSequence csq, int start, int end)
Appends a subsequence of the specified character sequence to this writer.
|
Writer
|
append(char c)
Appends the specified character to this writer.
|
abstract
void
|
close()
Closes the stream, flushing it first.
|
abstract
void
|
flush()
Flushes the stream.
|
void
|
write(char[] cbuf)
Writes an array of characters.
|
void
|
write(String str)
Writes a string.
|
abstract
void
|
write(char[] cbuf, int off, int len)
Writes a portion of an array of characters.
|
void
|
write(String str, int off, int len)
Writes a portion of a string.
|
void
|
write(int c)
Writes a single character.
|
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait()
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object.
|
final
void
|
wait(long timeout, int nanos)
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object, or
some other thread interrupts the current thread, or a certain
amount of real time has elapsed.
|
final
void
|
wait(long timeout)
Causes the current thread to wait until either another thread invokes the
notify() method or the
notifyAll() method for this object, or a
specified amount of time has elapsed.
|
|
From interface
java.io.Closeable
abstract
void
|
close()
Closes this stream and releases any system resources associated
with it.
|
|
From interface
java.io.Flushable
abstract
void
|
flush()
Flushes this stream by writing any buffered output to the underlying
stream.
|
|
From interface
java.lang.Appendable
|
Public Constructors
public
IndentingWriter
(Writer out)
Creates a new IndentingWriter that writes indented text to the
given Writer. Use the default indent step of four spaces.
public
IndentingWriter
(Writer out, int indentStep)
Creates a new IndentingWriter that writes indented text to the
given Writer and uses the supplied indent step.
public
IndentingWriter
(Writer out, int indentStep, int tabSize)
Creates a new IndentingWriter that writes indented text to the
given Writer and uses the supplied indent step and tab size.
Public Methods
public
void
newLine
()
Writes a line separator. The next character written will be
preceded by an indent.
public
void
pO
(String s)
Indents out; writes string.
public
void
pO
(Object o)
Indents out; writes object.
public
void
pOln
(Object o)
Indents out; writes object; ends current line.
public
void
pOln
(String s)
Indents out; writes string; ends current line.
public
void
pOlnI
(String s)
Indents out; writes string; ends current line; indents in.
This method is useful for generating lines of code that both
end and begin nested blocks, like "} else {".
public
void
pOlnI
(Object o)
Indents out; writes object; ends current line; indents in.
This method is useful for generating lines of code that both
end and begin nested blocks, like "} else {".
public
void
pln
(String s)
Writes string; ends current line.
public
void
pln
(Object o)
Writes object; ends current line.
public
void
plnI
(Object o)
Writes object; ends current line; indents in.
public
void
plnI
(String s)
Writes string; ends current line; indents in.
public
void
write
(char[] cbuf, int off, int len)
Writes a portion of an array of characters.
Parameters
cbuf
| A character array |
off
| Offset from which to start reading characters |
len
| Number of characters to write |
public
void
write
(int c)
Writes a single character.
Parameters
c
| int specifying a character to be written |
public
void
write
(String s, int off, int len)
Writes a portion of a String.
Parameters
s
| String to be written |
off
| Offset from which to start reading characters |
len
| Number of characters to be written |
Protected Methods
protected
void
checkWrite
()
Checks if an indent needs to be written before writing the next
character.
The indent generation is optimized (and made consistent with
certain coding conventions) by condensing groups of eight
spaces into tab characters.
protected
void
indentIn
()
Increases the current indent by the indent step.
protected
void
indentOut
()
Decreases the current indent by the indent step.