Class IOPathUtils

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

public class IOPathUtils extends Object
  • 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
      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
      Returns:
      A new IOPath object with the new extension