From: Hannu Niemistö Date: Mon, 6 Feb 2017 11:01:11 +0000 (+0200) Subject: Filter out CR in resource files generated by graph compiler. X-Git-Tag: v1.28.0~84 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=1463e5c4bbbd37f7ff86abe25da59b3e39977cee;p=simantics%2Fplatform.git Filter out CR in resource files generated by graph compiler. Change-Id: I10e0dfe6a0726c001f63dd438c50256f4fc7cfe6 --- diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/FilterCRWriter.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/FilterCRWriter.java new file mode 100644 index 000000000..2e966754d --- /dev/null +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/FilterCRWriter.java @@ -0,0 +1,47 @@ +package org.simantics.graph.compiler.internal.resourceFiles; + +import java.io.FilterWriter; +import java.io.IOException; +import java.io.Writer; + +public class FilterCRWriter extends FilterWriter { + + public FilterCRWriter(Writer out) { + super(out); + } + + @Override + public void write(int c) throws IOException { + if(c != '\r') + out.write(c); + } + + @Override + public void write(char[] cbuf, int off, int len) throws IOException { + int begin = 0; + for(int i=0;i begin) + write(cbuf, off+begin, i-begin); + begin = i+1; + } + } + if(len > begin) + write(cbuf, off+begin, len-begin); + } + + @Override + public void write(String str, int off, int len) throws IOException { + int begin = 0; + for(int i=0;i begin) + write(str, off+begin, i-begin); + begin = i+1; + } + } + if(len > begin) + write(str, off+begin, len-begin); + } + +} diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFile.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFile.java index c7e1f22b1..d9d155037 100644 --- a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFile.java +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFile.java @@ -6,6 +6,7 @@ import java.io.OutputStreamWriter; import java.io.StringWriter; import java.io.Writer; import java.net.URL; +import java.nio.charset.Charset; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -19,6 +20,8 @@ import freemarker.template.DefaultObjectWrapper; import freemarker.template.Template; public class ResourceFile implements IResourceFile { + private final static Charset UTF8 = Charset.forName("UTF-8"); + String packageName; String className; List resources; @@ -88,8 +91,8 @@ public class ResourceFile implements IResourceFile { @Override public InputStream getContent() { StringWriter writer = new StringWriter(); - write(writer); - return new ByteArrayInputStream(writer.toString().replace("\r\n", "\n").getBytes()); + write(new FilterCRWriter(writer)); + return new ByteArrayInputStream(writer.toString().getBytes(UTF8)); } /* (non-Javadoc)