Package org.apache.calcite.util
Class StackWriter
java.lang.Object
java.io.Writer
java.io.FilterWriter
org.apache.calcite.util.StackWriter
- All Implemented Interfaces:
- Closeable,- Flushable,- Appendable,- AutoCloseable
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 SummaryFieldsModifier and TypeFieldDescriptionstatic final intDirective for ending an SQL identifier.static final intDirective for ending an SQL string literal.static final intDirective for increasing the indentation level.static final StringFour-space indentation.static final StringTab indentation.static final intDirective for beginning an SQL identifier.static final intDirective for beginning an SQL string literal.static final intDirective for decreasing the indentation level.Fields inherited from class java.io.FilterWriterout
- 
Constructor SummaryConstructorsConstructorDescriptionStackWriter(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 SummaryModifier and TypeMethodDescriptionstatic voidprintSqlIdentifier(PrintWriter pw, String s) Writes an SQL identifier.static voidWrites an SQL string literal.voidwrite(char[] cbuf, int off, int len) voidwrite(int c) voidMethods inherited from class java.io.FilterWriterclose, flush
- 
Field Details- 
INDENTpublic static final int INDENTDirective for increasing the indentation level.- See Also:
 
- 
OUTDENTpublic static final int OUTDENTDirective for decreasing the indentation level.- See Also:
 
- 
OPEN_SQL_STRING_LITERALpublic static final int OPEN_SQL_STRING_LITERALDirective for beginning an SQL string literal.- See Also:
 
- 
CLOSE_SQL_STRING_LITERALpublic static final int CLOSE_SQL_STRING_LITERALDirective for ending an SQL string literal.- See Also:
 
- 
OPEN_SQL_IDENTIFIERpublic static final int OPEN_SQL_IDENTIFIERDirective for beginning an SQL identifier.- See Also:
 
- 
CLOSE_SQL_IDENTIFIERpublic static final int CLOSE_SQL_IDENTIFIERDirective for ending an SQL identifier.- See Also:
 
- 
INDENT_TABTab indentation.- See Also:
 
- 
INDENT_SPACE4Four-space indentation.- See Also:
 
 
- 
- 
Constructor Details- 
StackWriterCreates a new StackWriter on top of an existing Writer, with the specified string to be used for each level of indentation.- Parameters:
- writer- underlying writer
- indentation- indentation unit such as- INDENT_TABor- INDENT_SPACE4
 
 
- 
- 
Method Details- 
write- Overrides:
- writein class- FilterWriter
- Throws:
- IOException
 
- 
write- Overrides:
- writein class- FilterWriter
- Throws:
- IOException
 
- 
write- Overrides:
- writein class- FilterWriter
- Throws:
- IOException
 
- 
printSqlStringLiteralWrites an SQL string literal.- Parameters:
- pw- PrintWriter on which to write
- s- text of literal
 
- 
printSqlIdentifierWrites an SQL identifier.- Parameters:
- pw- PrintWriter on which to write
- s- identifier
 
 
-