Skip to content

Commit

Permalink
SamReaderFactory opens non-regular File and Path the same way (#1717)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshakir authored Oct 2, 2024
1 parent 966737b commit 4c1c766
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/htsjdk/samtools/SamReaderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public SamReader open(final Path path) {
public SamReader open(final Path path,
Function<SeekableByteChannel, SeekableByteChannel> dataWrapper,
Function<SeekableByteChannel, SeekableByteChannel> indexWrapper) {
final SamInputResource r = SamInputResource.of(path, dataWrapper);
final SamInputResource r = dataWrapper == null
? SamInputResource.of(path)
: SamInputResource.of(path, dataWrapper);
final Path indexMaybe = SamFiles.findIndex(path);
if (indexMaybe != null) r.index(indexMaybe, indexWrapper);
return open(r);
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/htsjdk/samtools/SamReaderFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,17 @@ public void openPath() throws IOException {
}
}

@Test
public void testOpenIrregularPath() throws IOException {
// See: htsjdk.samtools.SamInputResource.of(java.nio.file.Path)
// Related to https://github.com/samtools/htsjdk/issues/1716
final File irregularFile = new File("/dev/null");
try (final SamReader fileReader = SamReaderFactory.makeDefault().open(irregularFile);
final SamReader pathReader = SamReaderFactory.makeDefault().open(irregularFile.toPath())) {
Assert.assertEquals(fileReader.getResourceDescription(), pathReader.getResourceDescription());
}
}

@DataProvider(name = "URIFallbackProvider")
public Object[][] URIFallbackProvider() throws MalformedURLException {
return new Object[][]{
Expand Down

0 comments on commit 4c1c766

Please sign in to comment.