Package htsjdk.io

# Interface IOPath

All Known Implementing Classes:
  `HtsPath`

public interface IOPath
Interface for htsjdk input/output paths/URIs.

## Method Summary

Modifier and Type
Method
Description
`default Optional<String>`
`getBaseName()`
`default Optional<String>`
`getExtension()`
`InputStream`
`getInputStream()`
Get a `InputStream` for this URI if a provider is for the URI's scheme is available.
`OutputStream`
`getOutputStream()`
Get an `OutputStream` for this URI if a provider is for the URI's scheme.
`String`
`getRawInputString()`
Return the raw input string that was provided to the constructor.
`default String`
`getScheme()`
Return the scheme for this `IOPath`.
`String`
`getToPathFailureReason()`
Return a string message describing why this URI cannot be converted to a `java.nio.file.Path` (`#isPath()` returns false).
`URI`
`getURI()`
Get a `java.net.URI` object for this `IOPath`.
`String`
`getURIString()`
Returns the string from which this `IOPath` 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 provided `extension` string.
`boolean`
`hasFileSystemProvider()`
`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 an `java.nio` Path.
`default boolean`
`isSam()`
Returns true if the file's extension is ".sam"".
`Path`
`toPath()`
Resolve this `IOPath` to an NIO `java.nio.file.Path`.

## Method Details

### getURI

URI getURI()
Get a `java.net.URI` object for this `IOPath`. Will not be null.

Returns:
  The `URI` object for this `IOPath`.

### getURIString

String getURIString()
Returns the string from which this `IOPath` was originally created. This string may differ from the normalized string returned from a `java.nio.file.Path` that has been object resolved from this `IOPath`.

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 a `java.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 an `java.nio` Path. If true, `#toPath()` can be safely called. There are cases where a valid URI with a valid scheme backed by an installed invalid input: '{@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 this `IOPath` to an NIO `java.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 a `java.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 this `IOPath`. 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 `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" (the `hasExtension(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 provided `extension` 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

default Optional<String> 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 a `InputStream` for this URI if a provider is for the URI's scheme is available.

Returns:
  `InputStream` for this URI.

### getOutputStream

OutputStream getOutputStream()
Get an `OutputStream` for this URI if a provider is for the URI's scheme.

Returns:
  `OutputStream` for this URI.