This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch STREAMPIPES-379
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/STREAMPIPES-379 by this push:
     new 34884f5  [STREAMPIPES-379] Runtime name is not shown in PLC4X S7 
adapter
34884f5 is described below

commit 34884f5119d546f45e074a2c4c3362a17f785dc0
Author: Philipp Zehnder <[email protected]>
AuthorDate: Wed Jun 9 15:34:24 2021 +0200

    [STREAMPIPES-379] Runtime name is not shown in PLC4X S7 adapter
---
 .../streampipes/manager/file/FileManager.java      | 32 +++++++++++++++++-----
 .../streampipes/manager/file/TestFileManager.java  | 14 +++++-----
 .../sdk/extractor/AbstractParameterExtractor.java  |  3 +-
 3 files changed, 34 insertions(+), 15 deletions(-)

diff --git 
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/file/FileManager.java
 
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/file/FileManager.java
index 382ee3b..7c794b8 100644
--- 
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/file/FileManager.java
+++ 
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/file/FileManager.java
@@ -19,6 +19,7 @@ package org.apache.streampipes.manager.file;
 
 import org.apache.commons.io.input.BOMInputStream;
 import org.apache.streampipes.model.client.file.FileMetadata;
+import org.apache.streampipes.sdk.helpers.Filetypes;
 import org.apache.streampipes.storage.api.IFileMetadataStorage;
 import org.apache.streampipes.storage.management.StorageDispatcher;
 
@@ -29,15 +30,22 @@ import java.util.UUID;
 
 public class FileManager {
 
+  /**
+   * Store a file in the internal file storage.
+   * For csv files the bom is removed
+   * @param user who created the file
+   * @param filename
+   * @param fileInputStream content of file
+   * @return
+   * @throws IOException
+   */
   public static FileMetadata storeFile(String user,
                                String filename,
                                InputStream fileInputStream) throws IOException 
{
 
     String filetype = filename.substring(filename.lastIndexOf(".") + 1);
 
-    if ("csv".equals(filetype)) {
-      fileInputStream = removeBom(fileInputStream);
-    }
+    fileInputStream = cleanFile(fileInputStream, filetype);
 
     String internalFilename = makeInternalFilename(filetype);
     FileMetadata fileMetadata = makeFileMetadata(user, filename, 
internalFilename, filetype);
@@ -56,6 +64,20 @@ public class FileManager {
     return new FileHandler().getFile(filename);
   }
 
+  /**
+   * Remove Byte Order Mark (BOM) from csv files
+   * @param fileInputStream
+   * @param filetype
+   * @return
+   */
+  public static InputStream cleanFile(InputStream fileInputStream, String 
filetype) {
+    if (Filetypes.CSV.getFileExtensions().contains(filetype.toLowerCase())) {
+      fileInputStream = new BOMInputStream(fileInputStream);
+    }
+
+    return fileInputStream;
+  }
+
   private static void storeFileMetadata(FileMetadata fileMetadata) {
     getFileMetadataStorage().addFileMetadata(fileMetadata);
   }
@@ -86,8 +108,4 @@ public class FileManager {
     return UUID.randomUUID().toString() + "." + filetype;
   }
 
-  public static InputStream removeBom(InputStream stream) {
-    return new BOMInputStream(stream);
-//      return stream;
-  }
 }
diff --git 
a/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/file/TestFileManager.java
 
b/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/file/TestFileManager.java
index 4eb3f06..d0c3092 100644
--- 
a/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/file/TestFileManager.java
+++ 
b/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/file/TestFileManager.java
@@ -29,35 +29,35 @@ import static org.junit.Assert.*;
 public class TestFileManager {
 
     @Test
-    public void testRemoveBomWithNoBom() throws IOException {
+    public void testCleanFileWithoutBom() throws IOException {
         String expected = "test";
         InputStream inputStream = IOUtils.toInputStream(expected, 
StandardCharsets.UTF_8);
-        InputStream resultStream = FileManager.removeBom(inputStream);
+        InputStream resultStream = FileManager.cleanFile(inputStream, "CSV");
         String resultString = IOUtils.toString(resultStream, 
StandardCharsets.UTF_8);
 
         assertEquals(expected, resultString);
     }
 
     @Test
-    public void testRemoveBomWithBom() throws IOException {
+    public void testCleanFileWithBom() throws IOException {
         String expected = "test";
         String UTF8_BOM = "\uFEFF";
         String inputString = UTF8_BOM + expected;
         InputStream inputStream = IOUtils.toInputStream(inputString, 
StandardCharsets.UTF_8);
-        InputStream resultStream = FileManager.removeBom(inputStream);
+        InputStream resultStream = FileManager.cleanFile(inputStream, "CSV");
         String resultString = IOUtils.toString(resultStream, 
StandardCharsets.UTF_8);
 
         assertEquals(expected, resultString);
     }
 
     @Test
-    public void testRemoveBomWithBomAndUmlauts() throws IOException {
+    public void testCleanFileWithBomAndUmlauts() throws IOException {
         String expected = "testäüö";
         String UTF8_BOM = "\uFEFF";
         String inputString = UTF8_BOM + expected;
         InputStream inputStream = IOUtils.toInputStream(inputString, 
StandardCharsets.UTF_8);
-        InputStream resultStream = FileManager.removeBom(inputStream);
-        String resultString = IOUtils.toString(resultStream, 
StandardCharsets.ISO_8859_1);
+        InputStream resultStream = FileManager.cleanFile(inputStream, "CSV");
+        String resultString = IOUtils.toString(resultStream, 
StandardCharsets.UTF_8);
 
         assertEquals(expected, resultString);
     }
diff --git 
a/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/extractor/AbstractParameterExtractor.java
 
b/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/extractor/AbstractParameterExtractor.java
index cce79bc..6c698d3 100644
--- 
a/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/extractor/AbstractParameterExtractor.java
+++ 
b/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/extractor/AbstractParameterExtractor.java
@@ -19,6 +19,7 @@
 package org.apache.streampipes.sdk.extractor;
 
 import com.github.drapostolos.typeparser.TypeParser;
+import org.apache.commons.codec.Charsets;
 import org.apache.http.client.fluent.Request;
 import org.apache.streampipes.commons.exceptions.SpRuntimeException;
 import org.apache.streampipes.config.backend.BackendConfig;
@@ -109,7 +110,7 @@ public abstract class AbstractParameterExtractor<T extends 
InvocableStreamPipesE
 
   public String fileContentsAsString(String internalName) throws IOException {
     String filename = selectedFilename(internalName);
-    return 
Request.Get(makeFileRequestPath(filename)).execute().returnContent().asString();
+    return 
Request.Get(makeFileRequestPath(filename)).execute().returnContent().asString(Charsets.UTF_8);
   }
 
   public byte[] fileContentsAsByteArray(String internalName) throws 
IOException {

Reply via email to