From: Reino Ruusu Date: Wed, 25 Jan 2017 16:28:49 +0000 (+0200) Subject: Added SCLReportingWriter to org.simantics.scl.runtime. (refs #7000) X-Git-Tag: v1.27.0~2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F293%2F1;p=simantics%2Fplatform.git Added SCLReportingWriter to org.simantics.scl.runtime. (refs #7000) Change-Id: I2e988c0699bf228a3c13f80ac1917b202b2995f6 --- 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 index 000000000..5a12c7df8 --- /dev/null +++ b/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReportingWriter.java @@ -0,0 +1,44 @@ +package org.simantics.scl.runtime.reporting; + +import java.io.Writer; + +public class SCLReportingWriter extends Writer { + + StringBuilder builder = null; + + public SCLReportingWriter() { + builder = new StringBuilder(); + } + + @Override + public void close() { + flush(); + } + + @Override + public void flush() { + if (builder.length() > 0) { + SCLReporting.print(builder.toString()); + builder.setLength(0); + } + } + + @Override + public void write(char[] buf, int off, int len) { + if (len == 0) return; + + if (len < 0) throw new IllegalArgumentException("Negative buffer region length"); + if (off < 0) throw new IllegalArgumentException("Negative buffer region offset"); + if (off + len > buf.length) throw new IllegalArgumentException("Buffer region overflow"); + + for (int i = 0; i < len; i++) { + if (buf[off + i] == '\n') { + SCLReporting.print(builder.toString()); + builder.setLength(0); + } + else { + builder.append(buf[off + i]); + } + } + } +}