This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
YmlWriter.java
61 lines (47 loc) · 1.59 KB
/
YmlWriter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package eu.xenit.alfred.initializr.generator.io;
import io.spring.initializr.generator.io.IndentingWriter;
public class YmlWriter {
private final IndentingWriter writer;
private boolean prependIndent = false;
private boolean printSequenceIndicator = false;
private final char[] SEQUENCE_INDICATOR = "- ".toCharArray();
private final char[] TWO_SPACES = " ".toCharArray();
public YmlWriter(IndentingWriter writer) {
this.writer = writer;
}
public void println() {
this.writer.println();
this.prependIndent = true;
}
public void println(String string) {
write(string.toCharArray(), 0, string.length());
println();
}
public void indented(Runnable runnable) {
this.writer.indented(runnable);
}
public void sequenceElement(Runnable runnable) {
startSequence();
runnable.run();
endSequence();
}
private void startSequence() {
this.prependIndent = true;
this.printSequenceIndicator = true;
}
private void endSequence() {
this.prependIndent = false;
}
public void write(char[] chars, int offset, int length) {
if (this.prependIndent) {
if (this.printSequenceIndicator) {
this.writer.write(SEQUENCE_INDICATOR, 0, SEQUENCE_INDICATOR.length);
this.printSequenceIndicator = false;
} else {
this.writer.write(TWO_SPACES, 0, TWO_SPACES.length);
}
this.prependIndent = false;
}
this.writer.write(chars, offset, length);
}
}