Skip to content

Commit 1517c61

Browse files
authored
Merge pull request #937 from aalhossary/amr/fix934
Fix #934 Several file and path issues on windows
2 parents 01180f4 + cea40ed commit 1517c61

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

biojava-core/src/main/java/org/biojava/nbio/core/util/InputStreamProvider.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package org.biojava.nbio.core.util;
2424

2525
import java.io.*;
26+
import java.net.URISyntaxException;
2627
import java.net.URL;
2728
import java.util.Enumeration;
2829
import java.util.jar.JarEntry;
@@ -117,6 +118,14 @@ private int getMagicNumber(InputStream in)
117118

118119
public InputStream getInputStream(URL u)
119120
throws IOException{
121+
122+
if (u.getProtocol().equals("file")) {
123+
try {
124+
return getInputStream(new File(u.toURI().getPath()));
125+
} catch (URISyntaxException e) {
126+
throw new RuntimeException(e);
127+
}
128+
}
120129

121130
int magic = 0;
122131

biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import static org.junit.Assert.assertEquals;
44

5+
import java.io.File;
56
import java.io.IOException;
6-
import java.nio.file.Paths;
77
import java.util.List;
88

99
import org.biojava.nbio.structure.Group;
@@ -39,8 +39,7 @@ public void testRead() throws IOException {
3939
String resource = "org/biojava/nbio/structure/io/mmtf/4CUP.mmtf";
4040

4141
// Load the structure into memory
42-
Structure structure = MmtfActions.readFromFile((
43-
Paths.get(classLoader.getResource(resource).getPath())));
42+
Structure structure = MmtfActions.readFromFile(new File(classLoader.getResource(resource).getPath()).toPath());
4443

4544
// Check header properties of the structure
4645
assertEquals(structure.getPDBCode(), "4CUP");
@@ -61,8 +60,7 @@ public void compareMmcif() throws IOException, StructureException {
6160
String resource = "org/biojava/nbio/structure/io/mmtf/4CUP";
6261

6362
// Load the structures into memory
64-
Structure mmtf = MmtfActions.readFromFile((
65-
Paths.get(classLoader.getResource(resource + ".mmtf").getPath())));
63+
Structure mmtf = MmtfActions.readFromFile(new File(classLoader.getResource(resource + ".mmtf").getPath()).toPath());
6664
Structure mmcif = StructureIO.getStructure(classLoader.getResource(resource + ".cif").getPath());
6765

6866
// Compare the dates of the structure

biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureWriter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import java.io.File;
2424
import java.io.IOException;
25-
import java.nio.file.Paths;
2625
import java.util.ArrayList;
2726

2827
import org.biojava.nbio.structure.AminoAcidImpl;
@@ -66,7 +65,7 @@ public class TestMmtfStructureWriter {
6665
@Test
6766
public void testRead() throws IOException {
6867
ClassLoader classLoader = getClass().getClassLoader();
69-
Structure structure = MmtfActions.readFromFile((Paths.get(classLoader.getResource("org/biojava/nbio/structure/io/mmtf/4CUP.mmtf").getPath())));
68+
Structure structure = MmtfActions.readFromFile(new File(classLoader.getResource("org/biojava/nbio/structure/io/mmtf/4CUP.mmtf").getPath()).toPath());
7069
assertEquals(structure.getPDBCode(),"4CUP");
7170
assertEquals(structure.getChains().size(),6);
7271
}

0 commit comments

Comments
 (0)