Package bm.util
Class Util
java.lang.Object
bm.util.Util
A collection of generally useful things.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyFile(Path from, FileTarget to) Copies files and directories recursively.static voidCopies files and directories recursively.static FileTargetcreateFileCopyTarget(String target, String from) static FileTargetcreateFileCopyTarget(String target, Path from) static FileTargetcreateFileCopyTarget(Path target, Path from) Creates a target which usescopyFile(java.nio.file.Path, bm.target.FileTarget)to assure the target is a copy of the given file or directory.static voidDownloads data from a URL and saves it into the given path.static <I,O> List <O> NOTE: Yes, I know streams.static booleanThe Javadoc forPathtalks at great length about the "empty path", but they forgot to provide the respective test.static voidrecursiveDelete(String path) Recursively delete a directory.static voidrecursiveDelete(Path path) Recursively delete a directory.static StringFormats the duration as an integer with a time unit appended.
-
Method Details
-
recursiveDelete
Recursively delete a directory.- Parameters:
path- to delete- Throws:
BuildProblemException
-
recursiveDelete
Recursively delete a directory.- Parameters:
path- to delete- Throws:
BuildProblemException
-
download
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 downloadoutput- to write to- Throws:
BuildProblemException- to wrap an IOException
-
createFileCopyTarget
Creates a target which usescopyFile(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 perFileContentState.fromLastModified(Path)- Parameters:
target- name of file or directory to buildfrom- name of file or directory to copy from. Internally this is converted to aFileTargettoo.- Returns:
- a target with the file copy operation as the builder
-
createFileCopyTarget
-
createFileCopyTarget
-
copyFile
Copies files and directories recursively. SeecopyFile(Path, Path).- Throws:
BuildProblemException
-
copyFile
Copies files and directories recursively.- Parameters:
from- if it is a file, its contents will be copied into a fileto, if it is a directory, the same applies, i.e. all files and directories found infromare copied intoto. If necessary, a directorytois created.to- file or directory into which to copy- Throws:
BuildProblemException- iffromis a directory buttocannot be made into a directory, e.g. it exists as a file already
-
isEmpty
The Javadoc forPathtalks 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
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
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:
-