Package com.oopsclick.silk.utils
Class Tools
- java.lang.Object
-
- com.oopsclick.silk.utils.Tools
-
public class Tools extends java.lang.Object
The Class Tools provides multiple utility method to facility certain operations.- Author:
- Italo Osorio
-
-
Constructor Summary
Constructors Constructor Description Tools()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
base64ToBinary(java.lang.String data)
Converts a based64 text to binaryjava.lang.String
convertStreamToString(java.io.InputStream is)
Converts an InputStream to String using the the BufferedReader.readLine() method.int
createFolder(java.lang.String rootFolder, java.lang.String folderName)
Creates a folder inside the provided root folder.int
deleteFile(java.lang.String folder, java.lang.String fileName)
Deletes a file.java.lang.String
fileToBase64(java.io.File file)
Converts a file to Base64.java.lang.String
isNull(java.lang.String value, java.lang.String obj)
Check if the provided value is null.java.lang.String
readFile(java.lang.String filePath)
Reads a text based file.int
renameFile(java.lang.String folder, java.lang.String oldFileName, java.lang.String newFileName)
Renames a file.java.lang.String
replaceAll(java.lang.String source, java.lang.String toReplace, java.lang.String replacement)
Operates a replace all in a String using string search not using regular expression.java.util.Map<java.lang.String,java.lang.Object>
runtimeExec(java.lang.String command)
Executes the provided command into the operative system shell.int
writeFile(java.lang.String folder, java.lang.String name, byte[] content)
Writes a file with binary contentint
writeFile(java.lang.String folder, java.lang.String name, java.lang.String text)
Saves a text based file.
-
-
-
Method Detail
-
isNull
public java.lang.String isNull(java.lang.String value, java.lang.String obj)
Check if the provided value is null. It not null it returns the provided value. If null it will return the provided alternative value.- Parameters:
value
- - The value to test.obj
- - The alternative value to return if value is null.- Returns:
- The selected value.
-
replaceAll
public java.lang.String replaceAll(java.lang.String source, java.lang.String toReplace, java.lang.String replacement)
Operates a replace all in a String using string search not using regular expression. No character scape necessary.- Parameters:
source
- - The target String.toReplace
- - The String to replace.replacement
- - The String to place instead.- Returns:
- The new string
-
convertStreamToString
public java.lang.String convertStreamToString(java.io.InputStream is)
Converts an InputStream to String using the the BufferedReader.readLine() method.- Parameters:
is
- The InputStream- Returns:
- The converted String
-
createFolder
public int createFolder(java.lang.String rootFolder, java.lang.String folderName)
Creates a folder inside the provided root folder.- Parameters:
rootFolder
- The target folderfolderName
- The folder to create- Returns:
- 0 if folder is not created. 1 if folder has been created.
-
readFile
public java.lang.String readFile(java.lang.String filePath)
Reads a text based file.- Parameters:
filePath
- The file path.- Returns:
- The file content.
-
writeFile
public int writeFile(java.lang.String folder, java.lang.String name, java.lang.String text)
Saves a text based file.- Parameters:
folder
- The folder path.name
- The file nametext
- The content to save.- Returns:
- 0 if file is not saved. 1 if file has been saved.
-
writeFile
public int writeFile(java.lang.String folder, java.lang.String name, byte[] content)
Writes a file with binary content- Parameters:
folder
- The folder pathname
- The File namecontent
- The binary content- Returns:
- 0 if file is not saved. 1 if file has been saved.
-
renameFile
public int renameFile(java.lang.String folder, java.lang.String oldFileName, java.lang.String newFileName)
Renames a file.- Parameters:
folder
- The folder path.oldFileName
- The old name.newFileName
- The new name.- Returns:
- 0 if file was not renamed. 1 if file has been renamed.
-
deleteFile
public int deleteFile(java.lang.String folder, java.lang.String fileName)
Deletes a file.- Parameters:
folder
- The folder path.fileName
- The name of the file.- Returns:
- 0 if file was not deleted. 1 if file has been deleted.
-
fileToBase64
public java.lang.String fileToBase64(java.io.File file)
Converts a file to Base64.- Parameters:
file
- The file path.- Returns:
- The file content as base64
-
base64ToBinary
public byte[] base64ToBinary(java.lang.String data)
Converts a based64 text to binary- Parameters:
data
- The base64 content.- Returns:
- The content binary.
-
runtimeExec
public java.util.Map<java.lang.String,java.lang.Object> runtimeExec(java.lang.String command)
Executes the provided command into the operative system shell.- Parameters:
command
- The command to be executed- Returns:
- A Map list with the return results returning the "result" and the "output".
-
-