From 97783bff9fb5fadf57504350dba5d7cc0f6d615a Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Wed, 25 Jan 2017 18:28:49 +0200 Subject: [PATCH] Added SCLReportingWriter to org.simantics.scl.runtime. (refs #7000) Change-Id: I2e988c0699bf228a3c13f80ac1917b202b2995f6 --- .../runtime/reporting/SCLReportingWriter.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReportingWriter.java 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]); + } + } + } +} -- 2.47.1