From 8b5a8ab0540649cb106e75b7699e2b41a40e1124 Mon Sep 17 00:00:00 2001 From: Aldrin Piri Date: Thu, 18 Jun 2015 19:47:30 -0400 Subject: [PATCH] NIFI-698: Wrapping test resource files in a URI to handle encoding issues as per JDK-4466485 --- .../org/apache/nifi/util/NiFiPropertiesTest.java | 13 ++++++++++--- .../java/org/apache/nifi/nar/NarUnpackerTest.java | 14 ++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/nifi/nifi-commons/nifi-properties/src/test/java/org/apache/nifi/util/NiFiPropertiesTest.java b/nifi/nifi-commons/nifi-properties/src/test/java/org/apache/nifi/util/NiFiPropertiesTest.java index 0751275222..9c1c8d75cb 100644 --- a/nifi/nifi-commons/nifi-properties/src/test/java/org/apache/nifi/util/NiFiPropertiesTest.java +++ b/nifi/nifi-commons/nifi-properties/src/test/java/org/apache/nifi/util/NiFiPropertiesTest.java @@ -23,6 +23,7 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; +import java.net.URISyntaxException; import java.nio.file.Path; import java.util.HashSet; import java.util.List; @@ -84,9 +85,15 @@ public class NiFiPropertiesTest { private NiFiProperties loadSpecifiedProperties(String propertiesFile) { - String file = NiFiPropertiesTest.class.getResource(propertiesFile).getFile(); + String filePath; + try { + filePath = NiFiPropertiesTest.class.getResource(propertiesFile).toURI().getPath(); + } catch (URISyntaxException ex) { + throw new RuntimeException("Cannot load properties file due to " + + ex.getLocalizedMessage(), ex); + } - System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, file); + System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, filePath); NiFiProperties properties = NiFiProperties.getInstance(); @@ -97,7 +104,7 @@ public class NiFiPropertiesTest { InputStream inStream = null; try { - inStream = new BufferedInputStream(new FileInputStream(file)); + inStream = new BufferedInputStream(new FileInputStream(filePath)); properties.load(inStream); } catch (final Exception ex) { throw new RuntimeException("Cannot load properties file due to " diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/NarUnpackerTest.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/NarUnpackerTest.java index 66e167ec82..3d3d6af397 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/NarUnpackerTest.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/NarUnpackerTest.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; @@ -173,9 +174,14 @@ public class NarUnpackerTest { } private NiFiProperties loadSpecifiedProperties(String propertiesFile) { - String file = NarUnpackerTest.class.getResource(propertiesFile).getFile(); - - System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, file); + String filePath; + try { + filePath = NarUnpackerTest.class.getResource(propertiesFile).toURI().getPath(); + } catch (URISyntaxException ex) { + throw new RuntimeException("Cannot load properties file due to " + + ex.getLocalizedMessage(), ex); + } + System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, filePath); NiFiProperties properties = NiFiProperties.getInstance(); @@ -186,7 +192,7 @@ public class NarUnpackerTest { InputStream inStream = null; try { - inStream = new BufferedInputStream(new FileInputStream(file)); + inStream = new BufferedInputStream(new FileInputStream(filePath)); properties.load(inStream); } catch (final Exception ex) { throw new RuntimeException("Cannot load properties file due to "