Class UtilIO
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
checkIfJarAndCopyToTemp
(String filename) static void
copyRecursive
(File src, File dst) Copies all the files and directories in 'src' into 'dst'.static void
copyToFile
(InputStream in, File file) static void
delete
(File f, UtilIO.FileTest test) Recursively deletes all files in path which pass the test.static void
Deletes all the file/directory and all of its childrenstatic @Nullable String
ensureFilePath
(String path) static @Nullable URL
Given a path which may or may not be a URL return a URLstatic URL
ensureUrlNotNull
(@Nullable String path) static File
fileExample
(String path) static File[]
findMatches
(File directory, String regex) Looks for file names which match the regex in the directory.static File
static String
getGithubURL
(String pkg, String app) static @Nullable String
Steps back until it finds the base BoofCV directory.static String
getSourcePath
(String pkg, String app) Constructs the path for a source code file residing in the examples or demonstrations directory In the case of the file not being in either directory, an empty string is returned The expected parameters are class.getPackage().getName(), class.getSimpleName()static int
indexOfSourceStart
(String code) Finds the first javadoc OR the start of the class, which ever comes first.listAllMime
(String directory, String type) Lists all files in the directory with an MIME type that contains the string "type"listByPrefix
(String directory, @Nullable String prefix, @Nullable String suffix) Loads a list of files with the specified prefix.listByRegex
(String directory, String regex) listFilesSorted
(File directory) Returns a list of all the children as a file and sorts themlistImages
(String directory, boolean sort) Lists all images in the directory using a regex and optionally sorts the listlistSmart
(String pathPattern, boolean sort, BoofLambdas.Filter<Path> filter) An intelligent image file search.listSmartImages
(String pathPattern, boolean sort) Same aslistSmart(String, boolean, BoofLambdas.Filter)
but adds a filter that looks for images based on their extension.static <T> T
static <T extends Configuration>
TloadConfig
(File file) Loads a BoofCVConfiguration
in a YAML format from the diskstatic CameraPinholeBrown
loadExampleIntrinsic
(MediaManager media, File exampleFile) Loads camera model for an example input file.static boolean
loadLibrary
(String libraryName) static void
loadLibrarySmart
(String libraryName) loadListStringYaml
(File file) Saves a list of strings from a YAML filestatic void
Convenience function which creates a directory and everything along its path if it does not exist.static void
Checks to directory exists.static BufferedReader
openBufferedReader
(String fileName) static @Nullable InputStream
openStream
(String path) static String
Searches for the root BoofCV directory and returns an absolute path from it.static String
pathExample
(String path) static URL
pathExampleURL
(String path) Returns an absolute path to the file that is relative to the example directorystatic @Nullable String
readAsString
(InputStream stream) Reads an entire file and converts it into a text stringstatic @Nullable String
readAsString
(String path) Reads an entire file and converts it into a text stringstatic int
readInt
(InputStream input) static String
readLine
(InputStream input, StringBuilder buffer) Reads a line from an input stream.static void
static void
saveConfig
(Configuration config, File file) Saves a BoofCVConfiguration
in a YAML format to diskstatic <C extends Configuration>
voidsaveConfig
(C config, C canonical, File file) Saves a BoofCVConfiguration
in a YAML format to disk.static void
saveListStringYaml
(List<String> list, File file) Saves a list of strings as a YAML filestatic void
savePoseListCsv
(List<Se3_F64> list, RotationType type, File file) Saves a list of 6-dof pose in a CSV format.static void
savePoseListCsv
(List<Se3_F64> list, RotationType type, OutputStream output) Saves a list of 6-dof pose in a CSV format.static String
selectFile
(boolean exitOnCancel) Opens up a dialog box asking the user to select a file.static String
simplifyJarPath
(String path) static URL
simplifyJarPath
(URL url) Jar paths don't work if they include up directory.static String
systemToUnix
(String path) static boolean
static void
write
(OutputStream output, String message)
-
Field Details
-
UTF8
- See Also:
-
IMAGE_REGEX
- See Also:
-
-
Constructor Details
-
UtilIO
public UtilIO()
-
-
Method Details
-
saveListStringYaml
Saves a list of strings as a YAML file -
loadListStringYaml
Saves a list of strings from a YAML file -
savePoseListCsv
Saves a list of 6-dof pose in a CSV format. Rotation matrix is converted into the specified encoding.- Parameters:
list
- (Input) List of posestype
- (Input) Format to use for rotation matrixfile
- (Output) Where it's written to.
-
savePoseListCsv
Saves a list of 6-dof pose in a CSV format. Rotation matrix is converted into the specified encoding.- Parameters:
list
- (Input) List of posestype
- (Input) Format to use for rotation matrixoutput
- (Output) Where it's written to.
-
saveConfig
Saves a BoofCVConfiguration
in a YAML format to disk -
saveConfig
Saves a BoofCVConfiguration
in a YAML format to disk. Only values which are different from the 'canonical' reference are saved. This can result in more concise and readable configurations but can cause problems in repeatability if the reference is changed in the future.- Parameters:
config
- (Input) The configuration which is to be savedcanonical
- (Input) A configuration that is compared against. Only what's not identical will be saved. IF null then a new configuration will be created using default constructor.file
- (Input) Reference to the file that the configuration will be saved at.
-
loadConfig
Loads a BoofCVConfiguration
in a YAML format from the disk -
pathExampleURL
Returns an absolute path to the file that is relative to the example directory- Parameters:
path
- File path relative to root directory- Returns:
- Absolute path to file
-
loadExampleIntrinsic
Loads camera model for an example input file. First checks to see if there's calibration specific to that file if not it looks to see if there is a directory wide one. If all fails it returns null. -
openBufferedReader
- Throws:
FileNotFoundException
-
ensureURL
Given a path which may or may not be a URL return a URL -
ensureUrlNotNull
-
ensureFilePath
-
simplifyJarPath
Jar paths don't work if they include up directory. this wills trip those out. -
systemToUnix
-
simplifyJarPath
-
openStream
-
readLine
Reads a line from an input stream.- Throws:
IOException
-
readInt
- Throws:
IOException
-
write
- Throws:
IOException
-
pathExample
-
fileExample
-
path
Searches for the root BoofCV directory and returns an absolute path from it.- Parameters:
path
- File path relative to root directory- Returns:
- Absolute path to file
-
getFileToBase
-
getPathToBase
Steps back until it finds the base BoofCV directory.- Returns:
- Path to the base directory.
-
selectFile
Opens up a dialog box asking the user to select a file. If the user cancels it either returns null or quits the program.- Parameters:
exitOnCancel
- If it should quit on cancel or not.- Returns:
- Name of the selected file or null if nothing was selected.
-
loadLibrarySmart
-
loadLibrary
-
save
-
load
-
deleteRecursive
Deletes all the file/directory and all of its children -
copyRecursive
Copies all the files and directories in 'src' into 'dst'. -
readAsString
Reads an entire file and converts it into a text string -
readAsString
Reads an entire file and converts it into a text string -
getSourcePath
Constructs the path for a source code file residing in the examples or demonstrations directory In the case of the file not being in either directory, an empty string is returned The expected parameters are class.getPackage().getName(), class.getSimpleName()- Parameters:
pkg
- package containing the classapp
- simple class name
-
getGithubURL
-
indexOfSourceStart
Finds the first javadoc OR the start of the class, which ever comes first. This does require some thought. The word class can easily be inside a comment. Comments may or may not be there. Always the potential for stray // -
listByPrefix
public static List<String> listByPrefix(String directory, @Nullable @Nullable String prefix, @Nullable @Nullable String suffix) Loads a list of files with the specified prefix.- Parameters:
directory
- Directory it looks inside ofprefix
- Prefix that the file must have. Null if no prefix.suffix
- Suffix that the file must have. Null if no suffix- Returns:
- List of files that are in the directory and match the prefix.
-
listSmart
public static List<String> listSmart(String pathPattern, boolean sort, BoofLambdas.Filter<Path> filter) An intelligent image file search. If the passed in string starts with "glob:" or "regex:" then it will use a glob or regex pattern to find the files. Otherwise it will see if it's a file or directory. If a file then just that file is returned in the list. If a directory then all the files in that directory are returned.
Because Windows uses backslash instead of forward slash things are more complex. You either need to modify the path to escape the backslash '\' -> '\\' or replace all backslashes with a forward slash. This isn't done automatically because REGEX uses backslashes too. In summary: Windows path like foo\bar needs to be changed to foo/bar or foo\\bar. If you know of a clean fix for this mess please create a PR on Github
- Parameters:
pathPattern
- Either a path to the file/directory or a glob/regex pattern.sort
- If the output should be sorted firstfilter
- A filter that provides better flexibility in deciding what's included- Returns:
- List of found files that matched all the patterns
-
listSmartImages
Same aslistSmart(String, boolean, BoofLambdas.Filter)
but adds a filter that looks for images based on their extension.- Parameters:
pathPattern
- Either a path to the file/directory or a glob/regex pattern.sort
- If the output should be sorted first- Returns:
- List of matching file paths
-
listImages
Lists all images in the directory using a regex and optionally sorts the list -
listByRegex
-
listFilesSorted
Returns a list of all the children as a file and sorts them -
listAll
-
listAllMime
Lists all files in the directory with an MIME type that contains the string "type" -
findMatches
Looks for file names which match the regex in the directory.
Example:
BoofMiscOps.findMatches(new File("/path/to/directory"), ".+jpg");- Parameters:
directory
- directoryregex
- file name regex- Returns:
- array of matching files
-
validURL
-
copyToFile
-
delete
Recursively deletes all files in path which pass the test.- Parameters:
f
- base directory or filetest
- The test- Throws:
IOException
- Exception if fails to delete a file
-
checkIfJarAndCopyToTemp
-
mkdirs
Convenience function which creates a directory and everything along its path if it does not exist. Also checks to make sure the path leads to a directory if it does exist- Parameters:
directory
- Path to the directory
-
mkdirs
Checks to directory exists. If it does and delete is true it will recursively delete it and all its children. Then creates the directory again. If delete is false then it callsmkdirs(File)
.- Parameters:
directory
- Path to the directorydelete
- if true it will delete the original directory
-