public class IndentingPrintWriter
extends java.io.PrintWriter
Constructor and Description |
---|
IndentingPrintWriter(java.io.File file)
Creates a new IndentingPrintWriter, without automatic line flushing, with
the specified file.
|
IndentingPrintWriter(java.io.File file,
java.lang.String csn)
Creates a new IndentingPrintWriter, without automatic line flushing, with
the specified file and charset.
|
IndentingPrintWriter(java.io.OutputStream out)
Create a new IndentingPrintWriter, without automatic line flushing, from
an existing OutputStream.
|
IndentingPrintWriter(java.io.OutputStream out,
boolean autoFlush)
Create a new IndentingPrintWriter from an existing OutputStream.
|
IndentingPrintWriter(java.lang.String fileName)
Creates a new IndentingPrintWriter, without automatic line flushing, with
the specified file name.
|
IndentingPrintWriter(java.lang.String fileName,
java.lang.String csn)
Creates a new IndentingPrintWriter, without automatic line flushing, with
the specified file name and charset.
|
IndentingPrintWriter(java.io.Writer out)
Create a new IndentingPrintWriter, without automatic line flushing.
|
IndentingPrintWriter(java.io.Writer out,
boolean autoFlush)
Create a new IndentingPrintWriter.
|
Modifier and Type | Method and Description |
---|---|
void |
addIndentation(int inc) |
static void |
addIndentation(java.io.PrintWriter pw,
int inc)
Tests a PrintWriter to see if it is an instance of and
IndentingPrintWriter, and if it is, add a specified amount of indentation.
|
int |
getIndentation() |
int |
getTabSize() |
java.lang.String |
indentationString() |
static int |
justWroteNewline(java.io.PrintWriter pw)
Tests a PrintWriter to see if it is an instance of IndentingPrintWriter,
and if so, returns 1 if a newline was the last character written and 0
otherwise.
|
static void |
main(java.lang.String[] args) |
void |
println() |
static int |
printOpening(java.io.PrintWriter pw,
java.lang.String str)
Prints a string to a PrintWriter.
|
void |
removeIndentation(int inc) |
static void |
removeIndentation(java.io.PrintWriter pw,
int inc)
Tests a PrintWriter to see if it is an instance of and
IndentingPrintWriter, and if it is, add a specified amount of indentation.
|
void |
setIndentation(int col) |
void |
setTabSize(int size) |
void |
write(char[] buf,
int off,
int len) |
void |
write(int c) |
void |
write(java.lang.String str,
int off,
int len) |
public IndentingPrintWriter(java.io.Writer out)
out
- A character-output streampublic IndentingPrintWriter(java.io.Writer out, boolean autoFlush)
out
- A character-output streamautoFlush
- A boolean; if true, the println, printf, or
format methods will flush the output bufferpublic IndentingPrintWriter(java.io.OutputStream out)
out
- An output streamOutputStreamWriter.OutputStreamWriter(java.io.OutputStream)
public IndentingPrintWriter(java.io.OutputStream out, boolean autoFlush)
out
- An output streamautoFlush
- A boolean; if true, the println, printf, or
format methods will flush the output bufferOutputStreamWriter.OutputStreamWriter(java.io.OutputStream)
public IndentingPrintWriter(java.lang.String fileName) throws java.io.FileNotFoundException
OutputStreamWriter
, which will encode characters using the
default charset for
this instance of the Java virtual machine.fileName
- The name of the file to use as the destination of this writer. If the file
exists then it will be truncated to zero size; otherwise, a new file will
be created. The output will be written to the file and is buffered.java.io.FileNotFoundException
- If the given string does not denote an existing, writable regular file and
a new regular file of that name cannot be created, or if some other error
occurs while opening or creating the filejava.lang.SecurityException
- If a security manager is present and checkWrite(fileName)
denies write access to the filepublic IndentingPrintWriter(java.lang.String fileName, java.lang.String csn) throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException
OutputStreamWriter
, which will encode characters using the provided
charset.fileName
- The name of the file to use as the destination of this writer. If the file
exists then it will be truncated to zero size; otherwise, a new file will
be created. The output will be written to the file and is buffered.csn
- The name of a supported charsetjava.io.FileNotFoundException
- If the given string does not denote an existing, writable regular file and
a new regular file of that name cannot be created, or if some other error
occurs while opening or creating the filejava.lang.SecurityException
- If a security manager is present and checkWrite(fileName)
denies write access to the filejava.io.UnsupportedEncodingException
- If the named charset is not supportedpublic IndentingPrintWriter(java.io.File file) throws java.io.FileNotFoundException
OutputStreamWriter
, which
will encode characters using the
default charset for
this instance of the Java virtual machine.file
- The file to use as the destination of this writer. If the file exists then
it will be truncated to zero size; otherwise, a new file will be created.
The output will be written to the file and is buffered.java.io.FileNotFoundException
- If the given file object does not denote an existing, writable regular
file and a new regular file of that name cannot be created, or if some
other error occurs while opening or creating the filejava.lang.SecurityException
- If a security manager is present and checkWrite(file.getPath())
denies write access to the filepublic IndentingPrintWriter(java.io.File file, java.lang.String csn) throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException
OutputStreamWriter
, which will encode characters using the provided
charset.file
- The file to use as the destination of this writer. If the file exists then
it will be truncated to zero size; otherwise, a new file will be created.
The output will be written to the file and is buffered.csn
- The name of a supported charsetjava.io.FileNotFoundException
- If the given file object does not denote an existing, writable regular
file and a new regular file of that name cannot be created, or if some
other error occurs while opening or creating the filejava.lang.SecurityException
- If a security manager is present and checkWrite(file.getPath())
denies write access to the filejava.io.UnsupportedEncodingException
- If the named charset is not supportedpublic void setIndentation(int col)
public void addIndentation(int inc)
public void removeIndentation(int inc)
public int getIndentation()
public java.lang.String indentationString()
public void setTabSize(int size)
public int getTabSize()
public void write(char[] buf, int off, int len)
write
in class java.io.PrintWriter
public void write(int c)
write
in class java.io.PrintWriter
public void println()
println
in class java.io.PrintWriter
public void write(java.lang.String str, int off, int len)
write
in class java.io.PrintWriter
public static void main(java.lang.String[] args)
public static void addIndentation(java.io.PrintWriter pw, int inc)
pw
- PrintWriter to testinc
- indentation to addpublic static void removeIndentation(java.io.PrintWriter pw, int inc)
pw
- PrintWriter to testinc
- indentation to addpublic static int justWroteNewline(java.io.PrintWriter pw)
pw
- PrintWriter to testpw
is an indenting print writer and just
wrote a newline.public static int printOpening(java.io.PrintWriter pw, java.lang.String str)
The purpose of this method is to facilitate the cuddling of opening delimiters. Suppose we want to write a block of items delimited by '[' and ']'. Then to keep everything aligned, we may want the opening string to be simply "[ " if there was nothing written before it, as in
[ name="joe" age=23 ]while if something was written before it (such as field name information), then we will want the openning string to be "[ \n", as in
personField=[ name="joe" age=23 ]