Package htsjdk.beta.io

# Class IOPathUtils

java.lang.Object
htsjdk.beta.io.IOPathUtils

public class IOPathUtils extends Object

## Constructor Summary

Constructors
Constructor
Description
`IOPathUtils()`

## Method Summary

Modifier and Type
Method
Description
`static <T extends IOPath>
T`
`appendExtension(IOPath path, String extension, Function<String,T> ioPathConstructor)`
Takes an IOPath and returns a new IOPath object that keeps the same name as the original, but with the new extension added.
`static IOPath`
`createTempPath(String prefix, String suffix)`
Create a temporary file using a given name prefix and name suffix and return a `Path`.
`static String`
`getStringFromPath(IOPath ioPath)`
Get the entire contents of an IOPath file as a string.
`static <T extends IOPath>
T`
`replaceExtension(IOPath path, String newExtension, Function<String,T> ioPathConstructor)`
Takes an IOPath and returns a new IOPath object that keeps the same basename as the original but with a new extension.
`static void`
`writeStringToPath(IOPath ioPath, String contents)`
Write a String to an IOPath.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### IOPathUtils

public IOPathUtils()

## Method Details

### createTempPath

public static IOPath createTempPath(String prefix, String suffix)
Create a temporary file using a given name prefix and name suffix and return a `Path`.

Parameters:
  `prefix` - file name prefix to use
  `suffix` - file name suffix to use
Returns:
  IOPath for a temporary file that will be deleted on exit
Throws:
  `IOException` - in IO failures

### getStringFromPath

public static String getStringFromPath(IOPath ioPath)
Get the entire contents of an IOPath file as a string.

Parameters:
  `ioPath` - ioPath to consume
Returns:
  a UTF-8 string representation of the file contents

### writeStringToPath

public static void writeStringToPath(IOPath ioPath, String contents)
Write a String to an IOPath.

Parameters:
  `ioPath` - path where contents should be written
  `contents` - a UTF-8 string to be written

### replaceExtension

public static <T extends IOPath> T replaceExtension(IOPath path, String newExtension, Function<String,T> ioPathConstructor)
Takes an IOPath and returns a new IOPath object that keeps the same basename as the original but with a new extension. Only the last component of the extension will be replaced, e.g. ("my.fasta.gz", ".tmp") -> "my.fasta.tmp". If the original path has no extension, an exception will be thrown. If the input IOPath was created from a rawInputString that specifies a relative local path, the new path will have a rawInputString that specifies an absolute path. Examples - ("test_na12878.bam", ".bai") -> "test_na12878.bai" - ("test_na12878.bam", "bai") -> "test_na12878.bai" - ("test_na12878.ext.bam, ".bai") -> "test_na12878.ext.md5"

Parameters:
  `path` - The original path
  `newExtension` - The new file extension. If no leading "." is provided as part of the new extension, one will be added.
  `ioPathConstructor` - a function that takes a string and returns an IOPath-derived class of type <T>
Returns:
  A new IOPath object with the new extension

### appendExtension

public static <T extends IOPath> T appendExtension(IOPath path, String extension, Function<String,T> ioPathConstructor)
Takes an IOPath and returns a new IOPath object that keeps the same name as the original, but with the new extension added. If no leading "." is provided as part of the new extension, one will be added. If the input IOPath was created from a rawInputString that specifies a relative local path, the new path will have a rawInputString that specifies an absolute path. Examples: - ("test_na12878.bam", ".bai") -> "test_na12878.bam.bai" - ("test_na12878.bam", "md5") -> "test_na12878.bam.md5"

Parameters:
  `path` - The original path
  `extension` - The file extension to add. If no leading "." is provided as part of the extension, one will be added.
  `ioPathConstructor` - a function that takes a string and returns an IOPath-derived class of type <T>
Returns:
  A new IOPath object with the new extension