Package bm.util

Class Util

java.lang.Object
bm.util.Util

public final class Util extends Object
A collection of generally useful things.
  • Method Details

    • recursiveDelete

      public static void recursiveDelete(String path) throws BuildProblemException
      Recursively delete a directory.
      Parameters:
      path - to delete
      Throws:
      BuildProblemException
    • recursiveDelete

      public static void recursiveDelete(Path path) throws BuildProblemException
      Recursively delete a directory.
      Parameters:
      path - to delete
      Throws:
      BuildProblemException
    • download

      public static void download(URL url, Path output) throws BuildProblemException
      Downloads data from a URL and saves it into the given path. If necessary, the directory for the output file is created, as is the output file itself.
      Parameters:
      url - to download
      output - to write to
      Throws:
      BuildProblemException - to wrap an IOException
    • createFileCopyTarget

      public static FileTarget createFileCopyTarget(Path target, Path from)
      Creates a target which uses copyFile(java.nio.file.Path, bm.target.FileTarget) to assure the target is a copy of the given file or directory. The source and target states are maintained per FileContentState.fromLastModified(Path)
      Parameters:
      target - name of file or directory to build
      from - name of file or directory to copy from. Internally this is converted to a FileTarget too.
      Returns:
      a target with the file copy operation as the builder
    • createFileCopyTarget

      public static FileTarget createFileCopyTarget(String target, Path from)
    • createFileCopyTarget

      public static FileTarget createFileCopyTarget(String target, String from)
    • copyFile

      public static void copyFile(Path from, FileTarget to) throws BuildProblemException
      Copies files and directories recursively. See copyFile(Path, Path).
      Throws:
      BuildProblemException
    • copyFile

      public static void copyFile(Path from, Path to) throws BuildProblemException
      Copies files and directories recursively.
      Parameters:
      from - if it is a file, its contents will be copied into a file to, if it is a directory, the same applies, i.e. all files and directories found in from are copied into to. If necessary, a directory to is created.
      to - file or directory into which to copy
      Throws:
      BuildProblemException - if from is a directory but to cannot be made into a directory, e.g. it exists as a file already
    • isEmpty

      public static boolean isEmpty(Path p)
      The Javadoc for Path talks at great length about the "empty path", but they forgot to provide the respective test.
      Parameters:
      p - path to test
      Returns:
      true if p is the empty path
    • scaledStamp

      public static String scaledStamp(Duration d)
      Formats the duration as an integer with a time unit appended.
      Parameters:
      d - to be formatted
      Returns:
      a time string in a form like 100ms, 300s, 100min
    • filterMap

      public static <I, O> List<O> filterMap(Iterable<I> source, Function<I,O> mapper)
      NOTE: Yes, I know streams. And I dislike them. Unchecked exceptions and bloated.
      Type Parameters:
      I -
      Parameters:
      mapper - transforms the input values and returns non-null if they shall be returned in the output
      Returns: