Package htsjdk.beta.io
Class IOPathUtils
java.lang.Object
htsjdk.beta.io.IOPathUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends IOPath>
TappendExtension
(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 aPath
.static String
getStringFromPath
(IOPath ioPath) Get the entire contents of an IOPath file as a string.static <T extends IOPath>
TreplaceExtension
(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.
-
Constructor Details
-
IOPathUtils
public IOPathUtils()
-
-
Method Details
-
createTempPath
Create a temporary file using a given name prefix and name suffix and return aPath
.- Parameters:
prefix
- file name prefix to usesuffix
- file name suffix to use- Returns:
- IOPath for a temporary file that will be deleted on exit
- Throws:
IOException
- in IO failures
-
getStringFromPath
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
Write a String to an IOPath.- Parameters:
ioPath
- path where contents should be writtencontents
- 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 pathnewExtension
- 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- 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 pathextension
- 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- Returns:
- A new IOPath object with the new extension
-