summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/IndentStream.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/IndentStream.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/IndentStream.java')
-rw-r--r--NET/worlds/scape/IndentStream.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/NET/worlds/scape/IndentStream.java b/NET/worlds/scape/IndentStream.java
new file mode 100644
index 0000000..b7bd27d
--- /dev/null
+++ b/NET/worlds/scape/IndentStream.java
@@ -0,0 +1,94 @@
+package NET.worlds.scape;
+
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+public class IndentStream extends PrintStream {
+ private boolean _atstart = true;
+ private int _indent = 0;
+
+ public IndentStream(OutputStream os) {
+ super(os);
+ }
+
+ public IndentStream(OutputStream os, boolean flush) {
+ super(os, flush);
+ }
+
+ public void indent(int step) {
+ this._indent += step;
+ }
+
+ public void indent() {
+ this.indent(2);
+ }
+
+ public void undent(int step) {
+ if (this._indent >= step) {
+ this._indent -= step;
+ } else {
+ this._indent = 0;
+ }
+ }
+
+ public void undent() {
+ this.undent(2);
+ }
+
+ public int curIndent() {
+ return this._indent;
+ }
+
+ private void startLine() {
+ for (int i = 0; i < this._indent; i++) {
+ super.write(32);
+ }
+
+ this._atstart = false;
+ }
+
+ @Override
+ public void write(int b) {
+ if (b == 10) {
+ this._atstart = true;
+ } else if (this._atstart) {
+ this.startLine();
+ }
+
+ super.write(b);
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) {
+ while (len > 0) {
+ int firstlen = 0;
+
+ while (firstlen < len && b[off + firstlen] != 10) {
+ firstlen++;
+ }
+
+ if (firstlen > 0) {
+ if (this._atstart) {
+ this.startLine();
+ }
+
+ super.write(b, off, firstlen);
+ off += firstlen;
+ len -= firstlen;
+ this._atstart = false;
+ firstlen = 0;
+ }
+
+ while (firstlen < len && b[off + firstlen] == 10) {
+ firstlen++;
+ }
+
+ if (firstlen > 0) {
+ super.write(b, off, firstlen);
+ off += firstlen;
+ len -= firstlen;
+ this._atstart = true;
+ }
+ }
+ }
+}