Class IOUtil


  • public class IOUtil
    extends Object
    • Constructor Detail

      • IOUtil

        public IOUtil()
    • Method Detail

      • writeFile

        public static String writeFile​(Object object,
                                       String absolutePath,
                                       String writerName)
        Writes a given object with a given writer to the local file system at the specified path.
        Parameters:
        object -
        absolutePath -
        writerName -
        Returns:
        absolute path the file is written to
      • writeFileToDefaultDir

        public static String writeFileToDefaultDir​(Object object,
                                                   String relativePath,
                                                   String writerName)
        Writes a given object with a given writer to the local file system to the default directory.
        Parameters:
        object -
        relativePath -
        writerName -
        Returns:
        absolute path the file is written to
      • writeFile

        public static String writeFile​(Object object,
                                       String absolutePath)
        Writes a given object with a suitable writer to the local file system at the specified path.
        Parameters:
        object -
        absolutePath -
        Returns:
        absolute path the file is written to
      • writeFileToDefaultDir

        public static String writeFileToDefaultDir​(Object object,
                                                   String relativePath)
        Writes a given object with a suitable writer to the local file system to the default directory.
        Parameters:
        object -
        relativePath -
        Returns:
        absolute path the file is written to
      • readFile

        public static <T> T readFile​(String path,
                                     String readerName)
        Reads a file with a given reader from the specified path. First, the path is used as a relative path to the resources folder to find a matching classpath file. Second, the path is used as a relative path to the default output directory (in the user home directory) to find a matching file. Third, the path is used as is to read a file from any location in the local file system.
        Parameters:
        path -
        readerName -
        Returns:
        object parsed from the file at the specified path
      • readFile

        public static <T> T readFile​(InputStream inputStream,
                                     String readerName)
        Reads a file with a given reader from the specified input stream.
        Parameters:
        inputStream -
        readerName -
        Returns:
        object parsed from the file at the specified input stream
      • readFile

        public static <T> T readFile​(String path,
                                     Class<T> clazz)
        Reads a file with a suitable reader from the specified path. First, the path is used as a relative path to the resources folder to find a matching classpath file. Second, the path is used as a relative path to the default output directory (in the user home directory) to find a matching file. Third, the path is used as is to read a file from any location in the local file system.
        Parameters:
        path - file path
        clazz - class of the object to find a suitable reader
        Returns:
        object parsed from the file at the specified path
      • readFile

        public static <T> T readFile​(InputStream inputStream,
                                     Class<T> clazz)
        Reads a file with a suitable reader from the specified input stream.
        Parameters:
        inputStream - input stream
        clazz - class of the object to find a suitable reader
        Returns:
        object parsed from the file at the specified input stream
      • readString

        public static <T> T readString​(String xmlString,
                                       Class<T> clazz)
        Reads an XML string with a suitable reader.
        Parameters:
        clazz - class of the object to find a suitable reader
        Returns:
        object parsed from the XML string
      • readString

        public static <T> T readString​(String objXML,
                                       String readerName)
        Reads a file with a given reader from a given String. This allows for in-memory conversion from String-XML to DataObjects.
        Type Parameters:
        T -
        Parameters:
        objXML - XML-String representation of an object
        readerName -
        Returns:
        Object parsed from the String
      • writeString

        public static String writeString​(Object object)
        Writes a given object with a suitable writer to a String.
        Parameters:
        object -
        Returns:
        string representation of the given object
      • writeString

        public static String writeString​(Object object,
                                         String writerName)
        Writes a given object with a given writer to a String.
        Parameters:
        object -
        writerName -
        Returns:
        string representation of the given object
      • getInputStream

        public static InputStream getInputStream​(String path)
        Returns a file input stream for the specified path. First, the path is used as a relative path to the resources folder to find a matching classpath file. Second, the path is used as a relative path to the default output directory (in the user home directory) to find a matching file. Third, the path is used as is to read a file from any location in the local file system.
        Parameters:
        path - file path
        Returns:
        file input stream or null
      • isEmptyDefaultDir

        public static boolean isEmptyDefaultDir()
        Checks whether the default directory is empty.
      • clearDefaultDir

        public static void clearDefaultDir()
        Clears the content of the default directory.
      • clearDir

        public static void clearDir​(File folder)
        Clears the content of the given directory.
      • unzip

        public static void unzip​(String zipFilePath,
                                 String destDirectory)
        Extracts a zip file specified by the zipFilePath to a directory specified by destDirectory (will be created if does not exists). First, the zipFilePath is used as a relative path to the resources folder to find a matching classpath file. Second, the zipFilePath is used as a relative path to the default output directory (in the user home directory) to find a matching file. Third, the zipFilePath is used as is to read a file from any location in the local file system.
        Parameters:
        zipFilePath -
        destDirectory -