--- /dev/null
+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