From d6531126cea206a1fa7ef4f6eb2299899a757d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Henning?= <stu114708@informatik.uni-kiel.de> Date: Tue, 29 Mar 2016 15:19:12 +0200 Subject: [PATCH] added IndentWriter --- .../kieker/analysis/util/IndentWriter.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/main/java/kieker/analysis/util/IndentWriter.java diff --git a/src/main/java/kieker/analysis/util/IndentWriter.java b/src/main/java/kieker/analysis/util/IndentWriter.java new file mode 100644 index 00000000..be9dd60c --- /dev/null +++ b/src/main/java/kieker/analysis/util/IndentWriter.java @@ -0,0 +1,61 @@ +package kieker.analysis.util; + +import java.io.IOException; +import java.io.Writer; + +public class IndentWriter extends Writer { + + private final Writer writer; + + private int indented = 0; + private char indentChar = DEFAULT_INDENT_CHAR; + private int indentLength = DEFAULT_INDENT_LENGTH; + + public static final char DEFAULT_INDENT_CHAR = '\t'; + public static final int DEFAULT_INDENT_LENGTH = 1; + + public IndentWriter(final Writer writer) { + super(); + this.writer = writer; + } + + public IndentWriter(final Writer writer, final char indentChar, final int indentLength) { + this(writer); + this.indentChar = indentChar; + this.indentLength = indentLength; + } + + public void indent() { + indented++; + } + + public void unindent() { + if (indented > 0) { + indented--; + } + } + + public void writeln(final String str) throws IOException { + writer.write(getIndentChars() + str + '\n'); + } + + private String getIndentChars() { + return new String(new char[indentLength]).replace('\0', indentChar); + } + + @Override + public void write(final char[] cbuf, final int off, final int len) throws IOException { + writer.write(cbuf, off, len); + } + + @Override + public void flush() throws IOException { + writer.flush(); + } + + @Override + public void close() throws IOException { + writer.close(); + } + +} -- GitLab