public class StackWriter extends 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.
|
static int |
INDENT
Directive for increasing the indentation level.
|
static String |
INDENT_SPACE4
Four-space indentation.
|
static String |
INDENT_TAB
Tab indentation.
|
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.
|
out| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
printSqlIdentifier(PrintWriter pw,
String s)
Writes an SQL identifier.
|
static void |
printSqlStringLiteral(PrintWriter pw,
String s)
Writes an SQL string literal.
|
void |
write(char[] cbuf,
int off,
int len) |
void |
write(int c) |
void |
write(String str,
int off,
int len) |
close, flushpublic 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
public StackWriter(Writer writer, String indentation)
writer - underlying writerindentation - indentation unit such as INDENT_TAB or
INDENT_SPACE4public void write(int c)
throws IOException
write in class FilterWriterIOExceptionpublic void write(char[] cbuf,
int off,
int len)
throws IOException
write in class FilterWriterIOExceptionpublic void write(String str, int off, int len) throws IOException
write in class FilterWriterIOExceptionpublic 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 - identifierCopyright © 2012-2022 Apache Software Foundation. All Rights Reserved.