UNPKG

@specs-feup/lara

Version:

A js port of the popular framework for building source-to-source compilers

238 lines 9.19 kB
import { JavaClasses } from "./util/JavaTypes.js"; /** * Utility methods related with input/output operations on files. */ export default class Io { /** * @param object - object to check * * @returns true if the given object is a Java file, false otherwise. */ static isJavaFile<T>(object: T): boolean; /** * * @param path - Path for the file creation * * @returns new File object with path given */ private static newFile; /** * * @param base - Parent pathname * @param path - Child pathname * * @returns a new File object from parent and child pathnames */ private static newFileWithBase; /** * Creates a folder. * * @param fileOrBaseFolder - File object or path to the base folder * @param optionalFile - Optional child pathname or file, if absolute ignores fileorBaseFolder * * @returns the created folder */ static mkdir(fileOrBaseFolder: JavaClasses.File | string, optionalFile?: JavaClasses.File | string): JavaClasses.File; /** * * If folderName is undefined, returns the OS temporary folder. * If defined, creates a new folder inside the system's temporary folder and returns it. * @param folderName - Optional name for the temporaray folder * * @returns the OS temporary folder or the created folder */ static getTempFolder(folderName?: string): JavaClasses.File; /** * Creates a randomly named folder in the OS temporary folder that is deleted when the virtual machine exits. * @returns the created temporary folder */ static newRandomFolder(): JavaClasses.File; /** * * @param fileOrBaseFolder - File object or path to the base folder * @param optionalFile - Optional child pathname or file, if absolute ignores fileorBaseFolder * * @returns new File object with path given */ static getPath(fileOrBaseFolder: string | JavaClasses.File, optionalFile?: JavaClasses.File | string): JavaClasses.File; /** * @param fileOrBaseFolder - File object or path to the base folder * @param optionalFile - Optional child pathname or file * * @returns the absolute path of the given file */ static getAbsolutePath(fileOrBaseFolder: JavaClasses.File | string, optionalFile?: JavaClasses.File | string): string; /** * * @param baseFolder - File object or path to the base folder * @param args - Patterns to match * * @returns the paths (files and folders) in the given folder, corresponding to the given base folder and argument patterns. */ static getPaths(baseFolder: string | JavaClasses.File, ...args: string[]): JavaClasses.File[]; /** * * @param baseFolder - File object or path to the base folder * @param args - Patterns to match * * @returns the folders in the given folder, corresponding to the given base folder and argument patterns. */ static getFolders(baseFolder: string | JavaClasses.File, ...args: string[]): JavaClasses.File[]; /** * The files inside the given folder that respects the given pattern. * * @param baseFolder - File object or path to the base folder * @param pattern - Pattern to match * @param isRecursive - If true, search recursively inside the folder * * @returns the files inside the given folder that respects the given pattern. */ static getFiles(baseFolder?: string | JavaClasses.File, pattern?: string | any[], isRecursive?: boolean): JavaClasses.File[]; /** * @param fileOrBaseFolder - File object or path to the base folder * @param optionalFile - Optional child pathname or file * * @returns a List with a string for each line of the given file */ static readLines(fileOrBaseFolder: string | JavaClasses.File, optionalFile?: JavaClasses.File | string): string[]; /** * @param fileOrBaseFolder - File object or path to the base folder * @param optionalFile - Optional child pathname or file * * @returns if the delete operation on the given file was successfull. */ static deleteFile(fileOrBaseFolder: string | JavaClasses.File, optionalFile?: JavaClasses.File | string): boolean; /** * @param args - Each argument is a file that will be deleted. */ static deleteFiles(...args: any): void; /** * Deletes a folder and its contents. * * @param folderPath - File object or path to the folder * * @returns true if both the contents and the folder could be deleted */ static deleteFolder(folderPath: string | JavaClasses.File): boolean; /** * Deletes the contents of a folder. * * @param folderPath - File object or path to the folder * * @returns true if the content of the folder could be deleted */ static deleteFolderContents(folderPath: string | JavaClasses.File): boolean; /** * * @param folderPath - File object or path to the folder * * @returns true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise */ static isFile(path: string | JavaClasses.File): boolean; /** * * @param folderPath - File object or path to the folder * * @returns true if and only if the file denoted by this abstract pathname exists and is a folder; false otherwise */ static isFolder(path: string | JavaClasses.File): boolean; static readJson(path: string): any; /** * @deprecated Use JSONtoFile from api/core/output.js instead */ static writeJson<T>(path: string, object: T): void; /** * * @param filepath - path to the file to be copied * @param destination - path to the destination file * * @returns true if the file was copied successfully */ static copyFile(filepath: string | JavaClasses.File, destination: string | JavaClasses.File): boolean; /** * * @param filepath - path to the file to be copied * @param destination - path to the destination file * @param verbose - enables additional information * * @returns true if the folder was copied successfully */ static copyFolder(filepath: string | JavaClasses.File, destination: string, verbose?: boolean): boolean; /** * * @param path - base path * * @returns the given path, without extension. * */ static removeExtension(path: string | JavaClasses.File): string; /** * * @param path - base path * * @returns the extension of the given path. * */ static getExtension(path: string | JavaClasses.File): string; /** * @param path - The path of the file to write. * @param content - The contents to write. * * @returns The file to where the contents where written. */ static writeFile(path: string | JavaClasses.File, content: string): JavaClasses.File; /** * @param path - The path of the file to read. * * @returns The contents of the file. */ static readFile(path: string | JavaClasses.File): string; /** * * @param path - The path of the file to append * @param content - The content to append * * @returns true if the content was appended successfully */ static appendFile(path: string | JavaClasses.File, content: any): void; /** * * @param targetFile - The target file for which the relative path is calculated. * @param baseFile - The base file against which the relative path is calculated * * @returns the path of 'targetFile', relative to 'baseFile' or undefined if the file does not share a common ancestor with baseFile. */ static getRelativePath(targetFile: string | JavaClasses.File, baseFile: string | JavaClasses.File): string | undefined; /** * @returns the system-dependent path-separator (e.g., : or ;). */ static getPathSeparator(): string; /** * @returns system-dependent name-separator (e.g., / or \). */ static getSeparator(): string; /** * * @param fileOrBaseFolder - File object or path to the file * @param optionalFile - Optional child pathname or file * * @returns the MD5 checksum of the file represented as a hexadecimal string. * * @throws RuntimeException if there are any issues while reading the file or calculating the MD5 checksum */ static md5(fileOrBaseFolder: string | JavaClasses.File, optionalFile?: string | JavaClasses.File): string; /** * * @returns the current working directory as a File object. */ static getWorkingFolder(): JavaClasses.File; /** * If value is a string that ends in .json, assume it is a file to a json object and parses it. * If it is a string but does not end in json, assume it is a stringified object. * Otherwise, returns the object as it is. * * @deprecated Use JSON.parse() instead or fileToJSON from api/core/output.js */ static jsonObject<T>(value: T): T | string; } //# sourceMappingURL=Io.d.ts.map