|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.Writer java.io.FilterWriter org.eigenbase.util.StackWriter
public class StackWriter
A helper class for generating formatted text. StackWriter keeps track of nested formatting state like indentation level and quote escaping. Typically, it is inserted between a PrintWriter and the real Writer; directives are passed straight through the PrintWriter via the write method, as in the following example:
StringWriter sw = new StringWriter();
StackWriter stackw = new StackWriter(sw, StackWriter.INDENT_SPACE4);
PrintWriter pw = new PrintWriter(stackw);
pw.write(StackWriter.INDENT);
pw.print("execute remote(link_name,");
pw.write(StackWriter.OPEN_SQL_STRING_LITERAL);
pw.println();
pw.write(StackWriter.INDENT);
pw.println("select * from t where c > 'alabama'");
pw.write(StackWriter.OUTDENT);
pw.write(StackWriter.CLOSE_SQL_STRING_LITERAL);
pw.println(");");
pw.write(StackWriter.OUTDENT);
pw.close();
System.out.println(sw.toString());
which produces the following output:
execute remote(link_name,'
select * from t where c > ''alabama''
');
Field Summary | |
---|---|
static int |
CLOSE_SQL_IDENTIFIER
directive for ending an SQL identifier |
static int |
CLOSE_SQL_STRING_LITERAL
directive for ending an SQL string literal |
private static Character |
doubleQuote
|
static int |
INDENT
directive for increasing the indentation level |
static String |
INDENT_SPACE4
four-space indentation |
static String |
INDENT_TAB
tab indentation |
private String |
indentation
|
private int |
indentationDepth
|
private boolean |
needIndent
|
static int |
OPEN_SQL_IDENTIFIER
directive for beginning an SQL identifier |
static int |
OPEN_SQL_STRING_LITERAL
directive for beginning an SQL string literal |
static int |
OUTDENT
directive for decreasing the indentation level |
private LinkedList |
quoteStack
|
private static Character |
singleQuote
|
Fields inherited from class java.io.FilterWriter |
---|
out |
Fields inherited from class java.io.Writer |
---|
lock |
Constructor Summary | |
---|---|
StackWriter(Writer writer,
String indentation)
Creates a new StackWriter on top of an existing Writer, with the specified string to be used for each level of indentation. |
Method Summary | |
---|---|
private void |
indentIfNeeded()
|
private void |
popQuote(Character quoteChar)
|
static void |
printSqlIdentifier(PrintWriter pw,
String s)
Writes an SQL identifier. |
static void |
printSqlStringLiteral(PrintWriter pw,
String s)
Writes an SQL string literal. |
private void |
pushQuote(Character quoteChar)
|
void |
write(char[] cbuf,
int off,
int len)
|
void |
write(int c)
|
void |
write(String str,
int off,
int len)
|
private void |
writeQuote(Character quoteChar)
|
Methods inherited from class java.io.FilterWriter |
---|
close, flush |
Methods inherited from class java.io.Writer |
---|
append, append, append, write, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int INDENT
public static final int OUTDENT
public static final int OPEN_SQL_STRING_LITERAL
public static final int CLOSE_SQL_STRING_LITERAL
public static final int OPEN_SQL_IDENTIFIER
public static final int CLOSE_SQL_IDENTIFIER
public static final String INDENT_TAB
public static final String INDENT_SPACE4
private static final Character singleQuote
private static final Character doubleQuote
private int indentationDepth
private String indentation
private boolean needIndent
private LinkedList quoteStack
Constructor Detail |
---|
public StackWriter(Writer writer, String indentation)
writer
- underyling writerindentation
- indentation unit such as INDENT_TAB
or INDENT_SPACE4
Method Detail |
---|
private void indentIfNeeded() throws IOException
IOException
private void writeQuote(Character quoteChar) throws IOException
IOException
private void pushQuote(Character quoteChar) throws IOException
IOException
private void popQuote(Character quoteChar) throws IOException
IOException
public void write(int c) throws IOException
write
in class FilterWriter
IOException
public void write(char[] cbuf, int off, int len) throws IOException
write
in class FilterWriter
IOException
public void write(String str, int off, int len) throws IOException
write
in class FilterWriter
IOException
public static void printSqlStringLiteral(PrintWriter pw, String s)
pw
- PrintWriter on which to writes
- text of literalpublic static void printSqlIdentifier(PrintWriter pw, String s)
pw
- PrintWriter on which to writes
- identifier
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |