|
38 | 38 | import java.net.URL;
|
39 | 39 | import java.nio.channels.SeekableByteChannel;
|
40 | 40 | import java.nio.file.FileSystemNotFoundException;
|
| 41 | +import java.nio.file.FileSystems; |
41 | 42 | import java.nio.file.Files;
|
42 | 43 | import java.nio.file.Path;
|
43 | 44 | import java.util.function.Function;
|
@@ -93,17 +94,22 @@ public static SamInputResource of(final File file) {
|
93 | 94 | /** Creates a {@link SamInputResource} reading from the provided resource, with no index. */
|
94 | 95 | public static SamInputResource of(final Path path) {
|
95 | 96 |
|
96 |
| - if (Files.isRegularFile(path) && Files.exists(path)) { |
97 |
| - return new SamInputResource(new PathInputResource(path)); |
98 |
| - } else { |
99 |
| - // in the case of named pipes and other non-seekable paths there's a bug in the implementation of |
100 |
| - // java's GZIPInputStream which inappropriately uses .available() and then gets confused with the result |
101 |
| - // of 0. For reference see: |
102 |
| - // https://bugs.java.com/view_bug.do?bug_id=7036144 |
103 |
| - // https://github.com/samtools/htsjdk/pull/1077 |
104 |
| - // https://github.com/samtools/htsjdk/issues/898 |
| 97 | + // in the case of named pipes and other non-seekable paths there's a bug in the implementation of |
| 98 | + // java's GZIPInputStream which inappropriately uses .available() and then gets confused with the result |
| 99 | + // of 0. For reference see: |
| 100 | + // https://bugs.java.com/view_bug.do?bug_id=7036144 |
| 101 | + // https://github.com/samtools/htsjdk/pull/1077 |
| 102 | + // https://github.com/samtools/htsjdk/issues/898 |
| 103 | + |
| 104 | + // This still doesn't support the case where someone is creating a named pipe in a non-default |
| 105 | + // file system and then using it as input and passing a GZIPed into the other end of the pipe. |
105 | 106 |
|
| 107 | + // To work around this bug, we fall back to using a FileInputResource rather than a PathInputResource |
| 108 | + // when we encounter a non-regular file using the default NIO filesystem (file://) |
| 109 | + if (path.getFileSystem() == FileSystems.getDefault() && !Files.isRegularFile(path)) { |
106 | 110 | return of(path.toFile());
|
| 111 | + } else { |
| 112 | + return new SamInputResource(new PathInputResource(path)); |
107 | 113 | }
|
108 | 114 | }
|
109 | 115 |
|
|
0 commit comments