Package htsjdk.io
Interface IOPath
- All Known Implementing Classes:
HtsPath
public interface IOPath
Interface for htsjdk input/output paths/URIs.
-
Method Summary
Modifier and TypeMethodDescriptionGet aInputStream
for this URI if a provider is for the URI's scheme is available.Get anOutputStream
for this URI if a provider is for the URI's scheme.Return the raw input string that was provided to the constructor.default String
Return the scheme for thisIOPath
.Return a string message describing why this URI cannot be converted to ajava.nio.file.Path
(#isPath()
returns false).getURI()
Get ajava.net.URI
object for thisIOPath
.Returns the string from which thisIOPath
was originally created.default boolean
hasExtension
(String extension) Return true if the path component (the hierarchical part of the scheme specific part of the underlying URI) ends with the providedextension
string.boolean
default boolean
isBam()
Returns true if the file's extension is ".bam"".default boolean
isCram()
Returns true if the GATKPath's extension is ".cram".default boolean
isFasta()
boolean
isPath()
Return true if this {code IOPath} can be resolved to anjava.nio
Path.default boolean
isSam()
Returns true if the file's extension is ".sam"".toPath()
Resolve thisIOPath
to an NIOjava.nio.file.Path
.
-
Method Details
-
getURI
URI getURI()Get ajava.net.URI
object for thisIOPath
. Will not be null.- Returns:
- The
URI
object for thisIOPath
.
-
getURIString
String getURIString()Returns the string from which thisIOPath
was originally created. This string may differ from the normalized string returned from ajava.nio.file.Path
that has been object resolved from thisIOPath
.- Returns:
- string from which this URI as originally created. Will not be null.
-
getRawInputString
String getRawInputString()Return the raw input string that was provided to the constructor. -
hasFileSystemProvider
boolean hasFileSystemProvider()- Returns:
- true if this URI has a scheme that has an installed
java.nio
file system provider (). This does not guarantee the URI can be converted into ajava.nio.file.Path
, since the URI can be syntactically valid, and specify a valid file system provider, but still fail to be semantically meaningful.
-
isPath
boolean isPath()Return true if this {code IOPath} can be resolved to anjava.nio
Path. If true,#toPath()
can be safely called. There are cases where a valid URI with a valid scheme backed by an installed {@code java.nio File System still can't be turned into a {@code java.nio.file.Path}, i.e., the following specifies an invalid authority "namenode": hdfs://namenode/to/file The current implementation returns false for these cases (toPath will fail, getInvalidPathReason returns the reason code). -
toPath
Path toPath()Resolve thisIOPath
to an NIOjava.nio.file.Path
. Can be safely called only if#isPath()
returns true. -
getToPathFailureReason
String getToPathFailureReason()Return a string message describing why this URI cannot be converted to ajava.nio.file.Path
(#isPath()
returns false).- Returns:
- Message explaining toPath failure reason, since it can fail for various reasons.
-
getScheme
Return the scheme for thisIOPath
. For file URIs (URIs that have no explicit scheme), this will return the scheme "file".- Returns:
- the scheme String or this URI, if any. May be null.
-
getExtension
- Returns:
- an
Optional
containing the extension of the last component of the hierarchical part of the scheme-specific part of the URI, if any, including the ".", or Optional.empty() if the hierarchical name ends with the default file system separator, (i.e. "/"), or if the hierarchical name ends with a last component that does not contain a ".". Note that this only returns the part of the last component after the last ".", ie. it will return ".gz" for a name that ends in ".fasta.gz" (thehasExtension(String)
method can be used to test for the presence of multi-part extensions such as this).
-
hasExtension
Return true if the path component (the hierarchical part of the scheme specific part of the underlying URI) ends with the providedextension
string. This method can be used to test for both single and multi-part extensions (ie. for a name that ends in ".fasta.gz", it will return true for both ".gz" and ".fasta.gz".- Parameters:
extension
- the target extension to test, INCLUDING the leading ".". May not be null.- Returns:
- true if the path component of this specifier ends with the extension, otherwise false.
-
getBaseName
- Returns:
- an
Optional
containing the base name (the last component of the hierarchical part of the scheme-specific part of the URI, after the last "/"), up to but not including the extension (the last "."), or Optional.empty() if the last component is empty (ie, the component ends in "/"), or the last component exists but starts with "."
-
isSam
default boolean isSam()Returns true if the file's extension is ".sam"". -
isBam
default boolean isBam()Returns true if the file's extension is ".bam"". -
isCram
default boolean isCram()Returns true if the GATKPath's extension is ".cram". -
isFasta
default boolean isFasta()- Returns:
- true if this path spec has a FASTA file extension
-
getInputStream
InputStream getInputStream()Get aInputStream
for this URI if a provider is for the URI's scheme is available.- Returns:
InputStream
for this URI.
-
getOutputStream
OutputStream getOutputStream()Get anOutputStream
for this URI if a provider is for the URI's scheme.- Returns:
OutputStream
for this URI.
-