diff --git a/src/main/java/htsjdk/samtools/SamInputResource.java b/src/main/java/htsjdk/samtools/SamInputResource.java index d76694eeb..277c6e5fd 100644 --- a/src/main/java/htsjdk/samtools/SamInputResource.java +++ b/src/main/java/htsjdk/samtools/SamInputResource.java @@ -132,7 +132,13 @@ public SamInputResource index(final File file) { /** Updates the index to point at the provided resource, then returns itself. */ public SamInputResource index(final Path path) { - this.index = new PathInputResource(path, Function.identity()); + this.index = new PathInputResource(path); + return this; + } + + /** Updates the index to point at the provided resource, with the provided wrapper, then returns itself. */ + public SamInputResource index(final Path path, Function wrapper) { + this.index = new PathInputResource(path, wrapper); return this; } diff --git a/src/main/java/htsjdk/samtools/SamReaderFactory.java b/src/main/java/htsjdk/samtools/SamReaderFactory.java index a5eef5038..8f203d5c0 100644 --- a/src/main/java/htsjdk/samtools/SamReaderFactory.java +++ b/src/main/java/htsjdk/samtools/SamReaderFactory.java @@ -81,10 +81,28 @@ abstract public SamReader open(final File file); + /** + * Open the specified path (without using any wrappers). + * + * @param path the SAM or BAM file to open. + */ public SamReader open(final Path path) { - final SamInputResource r = SamInputResource.of(path, getPathWrapper()); + return open(path, null, null); + } + + /** + * Open the specified path, using the specified wrappers for prefetching/caching. + * + * @param path the SAM or BAM file to open + * @param dataWrapper the wrapper for the data (or null for none) + * @param indexWrapper the wrapper for the index (or null for none) + */ + public SamReader open(final Path path, + Function dataWrapper, + Function indexWrapper) { + final SamInputResource r = SamInputResource.of(path, dataWrapper); final Path indexMaybe = SamFiles.findIndex(path); - if (indexMaybe != null) r.index(indexMaybe); + if (indexMaybe != null) r.index(indexMaybe, indexWrapper); return open(r); } @@ -106,25 +124,6 @@ public SamReader open(final Path path) { /** Sets a specific Option to a boolean value. * */ abstract public SamReaderFactory setOption(final Option option, boolean value); - /** Sets a wrapper to modify the SeekableByteChannel from an opened Path, e.g. to add - * buffering or prefetching. This only works on Path inputs since we need a SeekableByteChannel. - * - * @param wrapper how to modify the SeekableByteChannel (Function.identity to unset) - * @return this - */ - public SamReaderFactory setPathWrapper(Function wrapper) { - this.pathWrapper = wrapper; - return this; - } - - /** Gets the wrapper previously set via setPathWrapper. - * - * @return the wrapper. - */ - public Function getPathWrapper() { - return pathWrapper; - } - /** Sets the specified reference sequence * */ abstract public SamReaderFactory referenceSequence(File referenceSequence); @@ -178,15 +177,10 @@ public static SamReaderFactory make() { private CRAMReferenceSource referenceSource; private SamReaderFactoryImpl(final EnumSet