]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added SCLReportingWriter to org.simantics.scl.runtime. (refs #7000) 93/293/1
authorReino Ruusu <reino.ruusu@vtt.fi>
Wed, 25 Jan 2017 16:28:49 +0000 (18:28 +0200)
committerReino Ruusu <reino.ruusu@vtt.fi>
Wed, 25 Jan 2017 16:28:49 +0000 (18:28 +0200)
Change-Id: I2e988c0699bf228a3c13f80ac1917b202b2995f6

bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReportingWriter.java [new file with mode: 0644]

diff --git a/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReportingWriter.java b/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReportingWriter.java
new file mode 100644 (file)
index 0000000..5a12c7d
--- /dev/null
@@ -0,0 +1,44 @@
+package org.simantics.scl.runtime.reporting;\r
+\r
+import java.io.Writer;\r
+\r
+public class SCLReportingWriter extends Writer {\r
+       \r
+       StringBuilder builder = null;\r
+       \r
+       public SCLReportingWriter() {\r
+               builder = new StringBuilder();\r
+       }\r
+       \r
+       @Override\r
+       public void close() {\r
+               flush();\r
+       }\r
+\r
+       @Override\r
+       public void flush() {\r
+               if (builder.length() > 0) {\r
+                       SCLReporting.print(builder.toString());\r
+                       builder.setLength(0);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void write(char[] buf, int off, int len) {\r
+               if (len == 0) return;\r
+               \r
+               if (len < 0) throw new IllegalArgumentException("Negative buffer region length");\r
+               if (off < 0) throw new IllegalArgumentException("Negative buffer region offset");\r
+               if (off + len > buf.length) throw new IllegalArgumentException("Buffer region overflow");\r
+               \r
+               for (int i = 0; i < len; i++) {\r
+                       if (buf[off + i] == '\n') {\r
+                               SCLReporting.print(builder.toString());\r
+                               builder.setLength(0);\r
+                       }\r
+                       else {\r
+                               builder.append(buf[off + i]);\r
+                       }\r
+               }\r
+       }\r
+}\r