Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SamReaderFactory opens non-regular File and Path the same way #1717

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading