Package com.jk.core.util
Class JKIOUtil
java.lang.Object
com.jk.core.util.JKIOUtil
The Class JKIOUtil.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic File
checkFolderPath
(String path, boolean create) Check folder path.static void
Clear temp files.static void
close
(InputStream inputStream) Close.static String
convertToString
(InputStream input) Convert to string.static void
copResourcesFromJarToDir
(String sourceClassPath, File dest) Cop resources from jar to dir.static void
createDirectory
(File parent, String name) Creates the directory.static void
createDirectory
(String path) Creates the directory.static void
createDirectory
(String parent, String name) Creates the directory.static File
Creates the temp directory.static File
createTempFile
(String ext) Creates the temp file.static boolean
Delete dir.static void
Delete dir.static void
deleteFile
(String templateFile) Delete file.static void
deleteFilesInDir
(String path) Delete files in dir.static Process
executeFile
(String fileName) Execute file.static void
exeutCommandAndWait
(File root, String command) Exeut command and wait.static String
findPathJar
(Class clas) If the provided class has been loaded from a jar file that is on the local file system, will find the absolute path to that jar file.getDirsInFolder
(String folder) Gets the dirs in folder.static String
getExtension
(String fileName, boolean withPoint) Gets the extension.static String
Gets the file separator.getFilesInFolder
(String folder, String ext) Gets the files in folder.static InputStream
getInputStream
(String name) Gets the input stream.static String
Gets the local host name.static Reader
Gets the reader.static InputStream
getReportFileAsStream
(String name) Gets the report file as stream.static String
getReportsOutPath
(boolean appendFileSeprator) Gets the reports out path.getResourcesInnPackage
(String root) Gets the resources inn package.static String
getSqlFile
(String fileName) Gets the sql file.getSubDirectories
(File directory) Gets the sub directories.static URL
Gets the url.static String
getUserFolderPath
(boolean appendFileSeprator) Gets the user folder path.static boolean
Checks if is empty.static boolean
isFileExist
(String fileName) Checks if is file exist.static boolean
Checks if is windows.static String
Read file.static String
Read file.static byte[]
readFileAsByteArray
(String fileName) Read file as byte array.static <T> T
readFileAsYaml
(String file, Class<T> clas) Read file as yaml.static Properties
readPropertiesFile
(File file) Read properties file.static Properties
readPropertiesFile
(String fileName) Read properties file.static Properties
readPropertiesStream
(InputStream inputStream) Read properties stream.static byte[]
readStream
(InputStream inStream) Read stream.static String
readStreamAsString
(InputStream inStream) Read stream as string.static String
removeExtension
(String fileName) Removes the extension.static void
Rename dir.static File
renameFile
(File file, String targetName) Rename file to a new name in the same path.static void
replaceValueInFile
(String fileName, String sourceValue, String targetValue) Replace value in file.static void
startFakeThread
(ServerSocket server) Start fake thread.static void
writeBytesToFile
(byte[] data, String localFile) Write bytes to file.static File
writeDataToFile
(byte[] data, File file) Write data to file.static File
writeDataToFile
(byte[] data, File file, boolean append) Write data to file.static void
writeDataToFile
(String data, File file) Write data to file.static void
writeDataToFile
(String text, String file) Write data to file.static File
writeDataToTempFile
(byte[] data, String suffix) Write data to temp file.static File
writeDataToTempFile
(String data, String ext) Write data to temp file.static File
writeFileToTempDirectory
(byte[] data, String fileName) Write file to temp directory.
-
Field Details
-
NEW_LINE
The Constant NEW_LINE.
-
-
Constructor Details
-
JKIOUtil
public JKIOUtil()
-
-
Method Details
-
findPathJar
If the provided class has been loaded from a jar file that is on the local file system, will find the absolute path to that jar file.- Parameters:
clas
- the clas- Returns:
- the string
- Throws:
IllegalStateException
- If the specified class was loaded from a directory or in some other way (such as via HTTP, from a database, or some other custom classloading device).
-
getInputStream
Gets the input stream.- Parameters:
name
- the name- Returns:
- the input stream
-
readPropertiesFile
Read properties file.- Parameters:
file
- the file- Returns:
- the properties
-
readStream
Read stream.- Parameters:
inStream
- the in stream- Returns:
- the byte[]
-
readStreamAsString
Read stream as string.- Parameters:
inStream
- the in stream- Returns:
- the string
-
convertToString
Convert to string.- Parameters:
input
- the input- Returns:
- the string
-
getUserFolderPath
Gets the user folder path.- Parameters:
appendFileSeprator
- the append file seprator- Returns:
- the user folder path
-
checkFolderPath
Check folder path.- Parameters:
path
- the pathcreate
- the create- Returns:
- the file
-
getReader
Gets the reader.- Parameters:
name
- the name- Returns:
- the reader
-
readFile
Read file.- Parameters:
string
- the string- Returns:
- the string
-
getExtension
Gets the extension.- Parameters:
fileName
- the file namewithPoint
- the with point- Returns:
- the extension
-
removeExtension
Removes the extension.- Parameters:
fileName
- the file name- Returns:
- the string
-
writeDataToFile
Write data to file.- Parameters:
data
- the datafile
- the file- Returns:
- the file
-
writeDataToFile
Write data to file.- Parameters:
data
- the datafile
- the fileappend
- the append- Returns:
- the file
-
readPropertiesStream
Read properties stream.- Parameters:
inputStream
- the input stream- Returns:
- the properties
-
close
Close.- Parameters:
inputStream
- the input stream
-
writeDataToTempFile
Write data to temp file.- Parameters:
data
- the datasuffix
- the suffix- Returns:
- the file
-
writeFileToTempDirectory
Write file to temp directory.- Parameters:
data
- the datafileName
- the file name- Returns:
- the file
-
createTempDirectory
Creates the temp directory.- Returns:
- the file
-
writeDataToTempFile
Write data to temp file.- Parameters:
data
- the dataext
- the ext- Returns:
- the file
-
createTempFile
Creates the temp file.- Parameters:
ext
- the ext- Returns:
- the file
-
getURL
Gets the url.- Parameters:
path
- the path- Returns:
- the url
-
readPropertiesFile
Read properties file.- Parameters:
fileName
- the file name- Returns:
- the properties
-
getReportFileAsStream
Gets the report file as stream.- Parameters:
name
- the name- Returns:
- the report file as stream
-
executeFile
Execute file.- Parameters:
fileName
- the file name- Returns:
- the process
-
getSqlFile
Gets the sql file.- Parameters:
fileName
- the file name- Returns:
- the sql file
-
getLocalHostName
Gets the local host name.- Returns:
- the local host name
-
readFileAsByteArray
Read file as byte array.- Parameters:
fileName
- the file name- Returns:
- the byte[]
-
writeBytesToFile
Write bytes to file.- Parameters:
data
- the datalocalFile
- the local file
-
isWindows
public static boolean isWindows()Checks if is windows.- Returns:
- true, if is windows
-
readFile
Read file.- Parameters:
file
- the file- Returns:
- the string
-
isFileExist
Checks if is file exist.- Parameters:
fileName
- the file name- Returns:
- true, if is file exist
-
createDirectory
Creates the directory.- Parameters:
path
- the path
-
isEmpty
Checks if is empty.- Parameters:
sqlFilePath
- the sql file path- Returns:
- true, if is empty
-
clearTempFiles
public static void clearTempFiles()Clear temp files. -
deleteDir
Delete dir.- Parameters:
dir
- the dir- Returns:
- true, if successful
-
startFakeThread
Start fake thread.- Parameters:
server
- the server
-
getReportsOutPath
Gets the reports out path.- Parameters:
appendFileSeprator
- the append file seprator- Returns:
- the reports out path
-
getFileSeparator
Gets the file separator.- Returns:
- the file separator
-
getFilesInFolder
Gets the files in folder.- Parameters:
folder
- the folderext
- the ext- Returns:
- the files in folder
-
getDirsInFolder
Gets the dirs in folder.- Parameters:
folder
- the folder- Returns:
- the dirs in folder
-
copResourcesFromJarToDir
Cop resources from jar to dir.- Parameters:
sourceClassPath
- the source class pathdest
- the dest
-
getResourcesInnPackage
Gets the resources inn package.- Parameters:
root
- the root- Returns:
- the resources inn package
-
writeDataToFile
Write data to file.- Parameters:
data
- the datafile
- the file
-
exeutCommandAndWait
Exeut command and wait.- Parameters:
root
- the rootcommand
- the command
-
writeDataToFile
Write data to file.- Parameters:
text
- the textfile
- the file
-
getSubDirectories
Gets the sub directories.- Parameters:
directory
- the directory- Returns:
- the sub directories
-
createDirectory
Creates the directory.- Parameters:
parent
- the parentname
- the name
-
createDirectory
Creates the directory.- Parameters:
parent
- the parentname
- the name
-
deleteDir
Delete dir.- Parameters:
fullPath
- the full path
-
replaceValueInFile
Replace value in file.- Parameters:
fileName
- the file namesourceValue
- the source valuetargetValue
- the target value
-
renameDir
Rename dir.- Parameters:
source
- the sourcedist
- the dist
-
renameFile
Rename file to a new name in the same path.- Parameters:
file
- the filetargetName
- the target name- Returns:
- the file
-
deleteFile
Delete file.- Parameters:
templateFile
- the template file
-
deleteFilesInDir
Delete files in dir.- Parameters:
path
- the path
-
readFileAsYaml
Read file as yaml.- Type Parameters:
T
- the generic type- Parameters:
file
- the fileclas
- the clas- Returns:
- the t
-