Skip to content
Snippets Groups Projects
Commit 078d69d2 authored by Maxime Journot's avatar Maxime Journot
Browse files

Fixed DataSourceTest.testFileName for Windows users.

Also added a constructor DataSource(URI) and a corresponding test.

Fixes #829
parent d9f46cde
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,9 @@
</properties>
<body>
<release version="11.0" date="TBD" description="TBD">
<action dev="maxime" type="fix" issue="829">
Fixed DataSourceTest.testFileName for Windows users.
</action>
<action dev="bryan" type="fix" issue="788" due-to="luc">
Fixed missing call to setMuCreated() in OemParser.
</action>
......
......@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.StandardCharsets;
......@@ -105,6 +106,14 @@ public class DataSource {
this(file.getName(), () -> new FileInputStream(file));
}
/** Build an instance from URI only.
* @param uri URI of the file
* @since 11.0
*/
public DataSource(final URI uri) {
this(Paths.get(uri).toFile());
}
/** Get the name of the data.
* @return name of the data
*/
......
......@@ -26,6 +26,7 @@ import java.io.Reader;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import org.junit.Assert;
import org.junit.Test;
......@@ -51,7 +52,7 @@ public class DataSourceTest {
@Test
public void testFileName() throws IOException, URISyntaxException {
URL url = DirectoryCrawlerTest.class.getClassLoader().getResource("regular-data/UTC-TAI.history");
DataSource ds = new DataSource(url.toURI().getPath());
DataSource ds = new DataSource(Paths.get(url.toURI()).toString());
Assert.assertTrue(ds.getName().endsWith("UTC-TAI.history"));
Assert.assertTrue(ds.getOpener().rawDataIsBinary());
try (InputStream is = ds.getOpener().openStreamOnce();
......@@ -73,6 +74,19 @@ public class DataSourceTest {
checkHistory(br);
}
}
@Test
public void testUri() throws IOException, URISyntaxException {
URL url = DirectoryCrawlerTest.class.getClassLoader().getResource("regular-data/UTC-TAI.history");
DataSource ds = new DataSource(url.toURI());
Assert.assertTrue(ds.getName().endsWith("UTC-TAI.history"));
Assert.assertTrue(ds.getOpener().rawDataIsBinary());
try (InputStream is = ds.getOpener().openStreamOnce();
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(isr)) {
checkHistory(br);
}
}
@Test
public void testDirectInputStream() throws IOException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment