From 1463e5c4bbbd37f7ff86abe25da59b3e39977cee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Mon, 6 Feb 2017 13:01:11 +0200 Subject: [PATCH] Filter out CR in resource files generated by graph compiler. Change-Id: I10e0dfe6a0726c001f63dd438c50256f4fc7cfe6 --- .../resourceFiles/FilterCRWriter.java | 47 +++++++++++++++++++ .../internal/resourceFiles/ResourceFile.java | 7 ++- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/FilterCRWriter.java 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) -- 2.47.1