Package htsjdk.io
Interface IOPath
-
- All Known Implementing Classes:
HtsPath
public interface IOPathInterface for htsjdk input/output paths/URIs.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Optional<String>getBaseName()default Optional<String>getExtension()InputStreamgetInputStream()Get aInputStreamfor this URI if a provider is for the URI's scheme is available.OutputStreamgetOutputStream()Get anOutputStreamfor this URI if a provider is for the URI's scheme.StringgetRawInputString()Return the raw input string that was provided to the constructor.default StringgetScheme()Return the scheme for thisIOPath.StringgetToPathFailureReason()Return a string message describing why this URI cannot be converted to ajava.nio.file.Path(#isPath()returns false).URIgetURI()Get ajava.net.URIobject for thisIOPath.StringgetURIString()Returns the string from which thisIOPathwas originally created.default booleanhasExtension(String extension)Return true if the path component (the hierarchical part of the scheme specific part of the underlying URI) ends with the providedextensionstring.booleanhasFileSystemProvider()default booleanisBam()Returns true if the file's extension is ".bam"".default booleanisCram()Returns true if the GATKPath's extension is ".cram".default booleanisFasta()booleanisPath()Return true if this {code IOPath} can be resolved to anjava.nioPath.default booleanisSam()Returns true if the file's extension is ".sam"".PathtoPath()Resolve thisIOPathto an NIOjava.nio.file.Path.
-
-
-
Method Detail
-
getURI
URI getURI()
Get ajava.net.URIobject for thisIOPath. Will not be null.- Returns:
- The
URIobject for thisIOPath.
-
getURIString
String getURIString()
Returns the string from which thisIOPathwas originally created. This string may differ from the normalized string returned from ajava.nio.file.Paththat 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.niofile 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.nioPath. 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 thisIOPathto 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
default String 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
default Optional<String> getExtension()
- Returns:
- an
Optionalcontaining 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
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 providedextensionstring. 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
default Optional<String> getBaseName()
- Returns:
- an
Optionalcontaining 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 aInputStreamfor this URI if a provider is for the URI's scheme is available.- Returns:
InputStreamfor this URI.
-
getOutputStream
OutputStream getOutputStream()
Get anOutputStreamfor this URI if a provider is for the URI's scheme.- Returns:
OutputStreamfor this URI.
-
-