Package org.machanism.machai.gw.tools
Class FileFunctionTools
java.lang.Object
org.machanism.machai.gw.tools.FileFunctionTools
- All Implemented Interfaces:
FunctionTools
Installs file-system tools into a
Genai.
Tools in this installer are intended for host-integrated use where the host controls the base working directory. All path provided to these tools are interpreted relative to the working directory supplied by the provider/runtime.
Installed tools
read_file– reads a file as textwrite_file– writes a file (creating parent directories as needed)list_files_in_directory– lists immediate children of a directoryget_recursive_file_list– recursively lists all files under a directory
- Author:
- Viktor Tovstyi
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyPatchToFile(String filePath, String patch, String charsetName, File projectDir) getRecursiveFiles(String path, File projectDir) Implementsget_recursive_file_list.getRecursiveFolders(String path, File projectDir) Implementsget_recursive_folder_list.static StringgetRelativePath(File dir, File file, boolean addSingleDot) Computes a project-relative path string.Implementslist_files_in_directory.Implementsread_file.Implementswrite_file.
-
Constructor Details
-
FileFunctionTools
public FileFunctionTools()
-
-
Method Details
-
getRecursiveFiles
Implementsget_recursive_file_list.Expected parameters:
JsonNodeoptionally containingdir_pathFileworking directory
-
getRecursiveFolders
Implementsget_recursive_folder_list.Expected parameters:
JsonNodeoptionally containingdir_pathFileworking directory
-
listFiles
Implementslist_files_in_directory.Expected parameters:
JsonNodeoptionally containingdir_pathFileworking directory
-
writeFile
Implementswrite_file. -
readFile
- Throws:
IOExceptionFileNotFoundException
-
getRelativePath
Computes a project-relative path string.The returned path always uses forward slashes (
/) for consistency across platforms.- Parameters:
dir- base directory used to relativize thefilefile- target file or directoryaddSingleDot- whether to prefix relative path with./- Returns:
- relative path,
.ifdirequalsfile, ornulliffileis not a descendant ofdir
-
applyPatchToFile
-