Class JKIOUtil

java.lang.Object
com.jk.core.util.JKIOUtil

public class JKIOUtil extends Object
The Class JKIOUtil.
  • Field Details

    • NEW_LINE

      public static final String NEW_LINE
      The Constant NEW_LINE.
  • Constructor Details

    • JKIOUtil

      public JKIOUtil()
  • Method Details

    • findPathJar

      public 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.
      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

      public static InputStream getInputStream(String name)
      Gets the input stream.
      Parameters:
      name - the name
      Returns:
      the input stream
    • readPropertiesFile

      public static Properties readPropertiesFile(File file)
      Read properties file.
      Parameters:
      file - the file
      Returns:
      the properties
    • readStream

      public static byte[] readStream(InputStream inStream)
      Read stream.
      Parameters:
      inStream - the in stream
      Returns:
      the byte[]
    • readStreamAsString

      public static String readStreamAsString(InputStream inStream)
      Read stream as string.
      Parameters:
      inStream - the in stream
      Returns:
      the string
    • convertToString

      public static String convertToString(InputStream input)
      Convert to string.
      Parameters:
      input - the input
      Returns:
      the string
    • getUserFolderPath

      public static String getUserFolderPath(boolean appendFileSeprator)
      Gets the user folder path.
      Parameters:
      appendFileSeprator - the append file seprator
      Returns:
      the user folder path
    • checkFolderPath

      public static File checkFolderPath(String path, boolean create)
      Check folder path.
      Parameters:
      path - the path
      create - the create
      Returns:
      the file
    • getReader

      public static Reader getReader(String name)
      Gets the reader.
      Parameters:
      name - the name
      Returns:
      the reader
    • readFile

      public static String readFile(String string)
      Read file.
      Parameters:
      string - the string
      Returns:
      the string
    • getExtension

      public static String getExtension(String fileName, boolean withPoint)
      Gets the extension.
      Parameters:
      fileName - the file name
      withPoint - the with point
      Returns:
      the extension
    • removeExtension

      public static String removeExtension(String fileName)
      Removes the extension.
      Parameters:
      fileName - the file name
      Returns:
      the string
    • writeDataToFile

      public static File writeDataToFile(byte[] data, File file)
      Write data to file.
      Parameters:
      data - the data
      file - the file
      Returns:
      the file
    • writeDataToFile

      public static File writeDataToFile(byte[] data, File file, boolean append)
      Write data to file.
      Parameters:
      data - the data
      file - the file
      append - the append
      Returns:
      the file
    • readPropertiesStream

      public static Properties readPropertiesStream(InputStream inputStream)
      Read properties stream.
      Parameters:
      inputStream - the input stream
      Returns:
      the properties
    • close

      public static void close(InputStream inputStream)
      Close.
      Parameters:
      inputStream - the input stream
    • writeDataToTempFile

      public static File writeDataToTempFile(byte[] data, String suffix)
      Write data to temp file.
      Parameters:
      data - the data
      suffix - the suffix
      Returns:
      the file
    • writeFileToTempDirectory

      public static File writeFileToTempDirectory(byte[] data, String fileName)
      Write file to temp directory.
      Parameters:
      data - the data
      fileName - the file name
      Returns:
      the file
    • createTempDirectory

      public static File createTempDirectory()
      Creates the temp directory.
      Returns:
      the file
    • writeDataToTempFile

      public static File writeDataToTempFile(String data, String ext)
      Write data to temp file.
      Parameters:
      data - the data
      ext - the ext
      Returns:
      the file
    • createTempFile

      public static File createTempFile(String ext)
      Creates the temp file.
      Parameters:
      ext - the ext
      Returns:
      the file
    • getURL

      public static URL getURL(String path)
      Gets the url.
      Parameters:
      path - the path
      Returns:
      the url
    • readPropertiesFile

      public static Properties readPropertiesFile(String fileName)
      Read properties file.
      Parameters:
      fileName - the file name
      Returns:
      the properties
    • getReportFileAsStream

      public static InputStream getReportFileAsStream(String name)
      Gets the report file as stream.
      Parameters:
      name - the name
      Returns:
      the report file as stream
    • executeFile

      public static Process executeFile(String fileName)
      Execute file.
      Parameters:
      fileName - the file name
      Returns:
      the process
    • getSqlFile

      public static String getSqlFile(String fileName)
      Gets the sql file.
      Parameters:
      fileName - the file name
      Returns:
      the sql file
    • getLocalHostName

      public static String getLocalHostName()
      Gets the local host name.
      Returns:
      the local host name
    • readFileAsByteArray

      public static byte[] readFileAsByteArray(String fileName)
      Read file as byte array.
      Parameters:
      fileName - the file name
      Returns:
      the byte[]
    • writeBytesToFile

      public static void writeBytesToFile(byte[] data, String localFile)
      Write bytes to file.
      Parameters:
      data - the data
      localFile - the local file
    • isWindows

      public static boolean isWindows()
      Checks if is windows.
      Returns:
      true, if is windows
    • readFile

      public static String readFile(File file)
      Read file.
      Parameters:
      file - the file
      Returns:
      the string
    • isFileExist

      public static boolean isFileExist(String fileName)
      Checks if is file exist.
      Parameters:
      fileName - the file name
      Returns:
      true, if is file exist
    • createDirectory

      public static void createDirectory(String path)
      Creates the directory.
      Parameters:
      path - the path
    • isEmpty

      public static boolean isEmpty(String sqlFilePath)
      Checks if is empty.
      Parameters:
      sqlFilePath - the sql file path
      Returns:
      true, if is empty
    • clearTempFiles

      public static void clearTempFiles()
      Clear temp files.
    • deleteDir

      public static boolean deleteDir(File dir)
      Delete dir.
      Parameters:
      dir - the dir
      Returns:
      true, if successful
    • startFakeThread

      public static void startFakeThread(ServerSocket server)
      Start fake thread.
      Parameters:
      server - the server
    • getReportsOutPath

      public static String getReportsOutPath(boolean appendFileSeprator)
      Gets the reports out path.
      Parameters:
      appendFileSeprator - the append file seprator
      Returns:
      the reports out path
    • getFileSeparator

      public static String getFileSeparator()
      Gets the file separator.
      Returns:
      the file separator
    • getFilesInFolder

      public static List<String> getFilesInFolder(String folder, String ext)
      Gets the files in folder.
      Parameters:
      folder - the folder
      ext - the ext
      Returns:
      the files in folder
    • getDirsInFolder

      public static List<String> getDirsInFolder(String folder)
      Gets the dirs in folder.
      Parameters:
      folder - the folder
      Returns:
      the dirs in folder
    • copResourcesFromJarToDir

      public static void copResourcesFromJarToDir(String sourceClassPath, File dest)
      Cop resources from jar to dir.
      Parameters:
      sourceClassPath - the source class path
      dest - the dest
    • getResourcesInnPackage

      public static List<File> getResourcesInnPackage(String root)
      Gets the resources inn package.
      Parameters:
      root - the root
      Returns:
      the resources inn package
    • writeDataToFile

      public static void writeDataToFile(String data, File file)
      Write data to file.
      Parameters:
      data - the data
      file - the file
    • exeutCommandAndWait

      public static void exeutCommandAndWait(File root, String command)
      Exeut command and wait.
      Parameters:
      root - the root
      command - the command
    • writeDataToFile

      public static void writeDataToFile(String text, String file)
      Write data to file.
      Parameters:
      text - the text
      file - the file
    • getSubDirectories

      public static List<String> getSubDirectories(File directory)
      Gets the sub directories.
      Parameters:
      directory - the directory
      Returns:
      the sub directories
    • createDirectory

      public static void createDirectory(String parent, String name)
      Creates the directory.
      Parameters:
      parent - the parent
      name - the name
    • createDirectory

      public static void createDirectory(File parent, String name)
      Creates the directory.
      Parameters:
      parent - the parent
      name - the name
    • deleteDir

      public static void deleteDir(String fullPath)
      Delete dir.
      Parameters:
      fullPath - the full path
    • replaceValueInFile

      public static void replaceValueInFile(String fileName, String sourceValue, String targetValue)
      Replace value in file.
      Parameters:
      fileName - the file name
      sourceValue - the source value
      targetValue - the target value
    • renameDir

      public static void renameDir(String source, String dist)
      Rename dir.
      Parameters:
      source - the source
      dist - the dist
    • renameFile

      public static File renameFile(File file, String targetName)
      Rename file to a new name in the same path.
      Parameters:
      file - the file
      targetName - the target name
      Returns:
      the file
    • deleteFile

      public static void deleteFile(String templateFile)
      Delete file.
      Parameters:
      templateFile - the template file
    • deleteFilesInDir

      public static void deleteFilesInDir(String path)
      Delete files in dir.
      Parameters:
      path - the path
    • readFileAsYaml

      public static <T> T readFileAsYaml(String file, Class<T> clas)
      Read file as yaml.
      Type Parameters:
      T - the generic type
      Parameters:
      file - the file
      clas - the clas
      Returns:
      the t