//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_of_fileNoPrefix() throws Exception public virtual void test_of_fileNoPrefix() { ResourceLocator test = ResourceLocator.of("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); assertEquals(test.Locator, "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); assertEquals(test.ByteSource.read()[0], 'H'); assertEquals(test.CharSource.readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.ToString(), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_ofPath() throws Exception public virtual void test_ofPath() { Path path = Paths.get("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); ResourceLocator test = ResourceLocator.ofPath(path); assertEquals(test.Locator.Replace('\\', '/'), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); assertEquals(test.ByteSource.read()[0], 'H'); assertEquals(test.CharSource.readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.ToString().Replace('\\', '/'), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_of_classpath() throws Exception public virtual void test_of_classpath() { ResourceLocator test = ResourceLocator.of("classpath:com/opengamma/strata/collect/io/TestFile.txt"); assertTrue(test.Locator.StartsWith("classpath", StringComparison.Ordinal)); assertTrue(test.Locator.EndsWith("com/opengamma/strata/collect/io/TestFile.txt", StringComparison.Ordinal)); assertEquals(test.ByteSource.read()[0], 'H'); assertEquals(test.CharSource.readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertTrue(test.ToString().StartsWith("classpath", StringComparison.Ordinal)); assertTrue(test.ToString().EndsWith("com/opengamma/strata/collect/io/TestFile.txt", StringComparison.Ordinal)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_ofPath_zipFile() throws Exception public virtual void test_ofPath_zipFile() { Path path = Paths.get("src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); ResourceLocator test = ResourceLocator.ofPath(path); assertEquals(test.Locator.Replace('\\', '/'), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); sbyte[] read = test.ByteSource.read(); assertEquals(read[0], 80); // these are the standard header of a zip file assertEquals(read[1], 75); assertEquals(read[2], 3); assertEquals(read[3], 4); assertEquals(test.ToString().Replace('\\', '/'), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_ofUrl() throws Exception public virtual void test_ofUrl() { File file = new File("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); URL url = file.toURI().toURL(); ResourceLocator test = ResourceLocator.ofUrl(url); string locator = test.Locator; assertTrue(locator.StartsWith("url:file:", StringComparison.Ordinal)); assertTrue(locator.EndsWith("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt", StringComparison.Ordinal)); assertEquals(test.ByteSource.read()[0], 'H'); assertEquals(test.CharSource.readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.ToString(), locator); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_equalsHashCode() throws Exception public virtual void test_equalsHashCode() { File file1 = new File("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); File file2 = new File("src/test/resources/com/opengamma/strata/collect/io/Other.txt"); ResourceLocator a1 = ResourceLocator.ofFile(file1); ResourceLocator a2 = ResourceLocator.ofFile(file1); ResourceLocator b = ResourceLocator.ofFile(file2); assertEquals(a1.Equals(a1), true); assertEquals(a1.Equals(a2), true); assertEquals(a1.Equals(b), false); assertEquals(a1.Equals(null), false); assertEquals(a1.Equals(ANOTHER_TYPE), false); assertEquals(a1.GetHashCode(), a2.GetHashCode()); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_orderedResources() throws Exception public virtual void test_orderedResources() { IList <ResourceLocator> list = ResourceConfig.orderedResources("TestFile.txt"); assertEquals(list.Count, 1); ResourceLocator test = list[0]; assertEquals(test.Locator.StartsWith("classpath", StringComparison.Ordinal), true); assertEquals(test.Locator.EndsWith("com/opengamma/strata/config/base/TestFile.txt", StringComparison.Ordinal), true); assertEquals(test.ByteSource.read()[0], 'H'); assertEquals(test.CharSource.readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.ToString().StartsWith("classpath", StringComparison.Ordinal), true); assertEquals(test.ToString().EndsWith("com/opengamma/strata/config/base/TestFile.txt", StringComparison.Ordinal), true); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_ofPath_fileInZipFile() throws Exception public virtual void test_ofPath_fileInZipFile() { Path zip = Paths.get("src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); using (FileSystem fs = FileSystems.newFileSystem(zip, null)) { Path path = fs.getPath("TestFile.txt").toAbsolutePath(); ResourceLocator test = ResourceLocator.ofPath(path); string locator = test.Locator; assertTrue(locator.StartsWith("url:jar:file:", StringComparison.Ordinal)); assertTrue(locator.EndsWith("src/test/resources/com/opengamma/strata/collect/io/TestFile.zip!/TestFile.txt", StringComparison.Ordinal)); assertEquals(test.ByteSource.read()[0], 'H'); assertEquals(test.CharSource.readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.ToString(), locator); } }
// find the list of resources //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static java.util.List<ResourceLocator> orderedResources0(String classpathResourceName) throws java.io.IOException private static IList <ResourceLocator> orderedResources0(string classpathResourceName) { ClassLoader classLoader = ResourceLocator.classLoader(); IList <string> names = new List <string>(); IList <ResourceLocator> result = new List <ResourceLocator>(); foreach (string dir in RESOURCE_DIRS) { string name = CONFIG_PACKAGE + dir + "/" + classpathResourceName; names.Add(name); IList <URL> urls = Collections.list(classLoader.getResources(name)); switch (urls.Count) { case 0: continue; case 1: result.Add(ResourceLocator.ofClasspathUrl(urls[0])); break; default: // handle case where Strata is on the classpath more than once // only accept this if the data being read is the same in all URLs ResourceLocator baseResource = ResourceLocator.ofClasspathUrl(urls[0]); for (int i = 1; i < urls.Count; i++) { ResourceLocator otherResource = ResourceLocator.ofClasspathUrl(urls[i]); if (!baseResource.ByteSource.contentEquals(otherResource.ByteSource)) { log.severe("More than one file found on the classpath: " + name + ": " + urls); throw new System.InvalidOperationException("More than one file found on the classpath: " + name + ": " + urls); } } result.Add(baseResource); break; } } if (result.Count == 0) { log.severe("No resource files found on the classpath: " + names); throw new System.InvalidOperationException("No files found on the classpath: " + names); } log.config(() => "Resources found: " + result); return(result); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_of_invalid() throws Exception public virtual void test_of_invalid() { assertThrowsIllegalArg(() => ResourceLocator.of("classpath:http:https:file:/foobar.txt")); }