public void test_ofPath_zipFile() throws Exception { Path path = Paths.get("src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); ResourceLocator test = ResourceLocator.ofPath(path); assertEquals( test.getLocator().replace('\\', '/'), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); byte[] read = test.getByteSource().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"); }
public void test_ofPath_fileInZipFile() throws Exception { Path zip = Paths.get("src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); try (FileSystem fs = FileSystems.newFileSystem(zip, null)) { Path path = fs.getPath("TestFile.txt").toAbsolutePath(); ResourceLocator test = ResourceLocator.ofPath(path); String locator = test.getLocator(); assertTrue(locator.startsWith("url:jar:file:")); assertTrue(locator.endsWith("src/test/resources/com/opengamma/strata/collect/io/TestFile.zip!/TestFile.txt")); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.toString(), locator); } }
public void test_ofPath() throws Exception { Path path = Paths.get("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); ResourceLocator test = ResourceLocator.ofPath(path); assertEquals( test.getLocator().replace('\\', '/'), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().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"); }