public class StackWriter
extends java.io.FilterWriter
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'' ');
Modifier and Type | Field and Description |
---|---|
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 java.lang.Character |
DOUBLE_QUOTE |
static int |
INDENT
directive for increasing the indentation level
|
static java.lang.String |
INDENT_SPACE4
four-space indentation
|
static java.lang.String |
INDENT_TAB
tab indentation
|
private java.lang.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 java.util.Deque<java.lang.Character> |
quoteStack |
private static java.lang.Character |
SINGLE_QUOTE |
Constructor and Description |
---|
StackWriter(java.io.Writer writer,
java.lang.String indentation)
Creates a new StackWriter on top of an existing Writer, with the
specified string to be used for each level of indentation.
|
Modifier and Type | Method and Description |
---|---|
private void |
indentIfNeeded() |
private void |
popQuote(java.lang.Character quoteChar) |
static void |
printSqlIdentifier(java.io.PrintWriter pw,
java.lang.String s)
Writes an SQL identifier.
|
static void |
printSqlStringLiteral(java.io.PrintWriter pw,
java.lang.String s)
Writes an SQL string literal.
|
private void |
pushQuote(java.lang.Character quoteChar) |
void |
write(char[] cbuf,
int off,
int len) |
void |
write(int c) |
void |
write(java.lang.String str,
int off,
int len) |
private void |
writeQuote(java.lang.Character quoteChar) |
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 java.lang.String INDENT_TAB
public static final java.lang.String INDENT_SPACE4
private static final java.lang.Character SINGLE_QUOTE
private static final java.lang.Character DOUBLE_QUOTE
private int indentationDepth
private java.lang.String indentation
private boolean needIndent
private final java.util.Deque<java.lang.Character> quoteStack
public StackWriter(java.io.Writer writer, java.lang.String indentation)
writer
- underlying writerindentation
- indentation unit such as INDENT_TAB
or
INDENT_SPACE4
private void indentIfNeeded() throws java.io.IOException
java.io.IOException
private void writeQuote(java.lang.Character quoteChar) throws java.io.IOException
java.io.IOException
private void pushQuote(java.lang.Character quoteChar) throws java.io.IOException
java.io.IOException
private void popQuote(java.lang.Character quoteChar) throws java.io.IOException
java.io.IOException
public void write(int c) throws java.io.IOException
write
in class java.io.FilterWriter
java.io.IOException
public void write(char[] cbuf, int off, int len) throws java.io.IOException
write
in class java.io.FilterWriter
java.io.IOException
public void write(java.lang.String str, int off, int len) throws java.io.IOException
write
in class java.io.FilterWriter
java.io.IOException
public static void printSqlStringLiteral(java.io.PrintWriter pw, java.lang.String s)
pw
- PrintWriter on which to writes
- text of literalpublic static void printSqlIdentifier(java.io.PrintWriter pw, java.lang.String s)
pw
- PrintWriter on which to writes
- identifierCopyright © 2012–2019 The Apache Software Foundation. All rights reserved.