Class IOUtil

java.lang.Object
de.uni_trier.wi2.procake.utils.io.IOUtil

public class IOUtil extends Object
  • Constructor Details

    • IOUtil

      public IOUtil()
  • Method Details

    • 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
    • createDirectories

      public static void createDirectories(String path)
      Creates all parent directories.
      Parameters:
      path - the path
    • writeStringToFile

      public static void writeStringToFile(Object obj, String path)
    • 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 - the path to create the input stream for
      readerName - the name of the reader to use
      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 - the input stream to read from
      readerName - the name of the reader to use
      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.
    • deleteFolder

      public static void deleteFolder(File folder)
      Deletes a given folder.
    • 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 it does not exist). 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 -
    • createZipFile

      public static void createZipFile(String zipFileDestination, List<File> files) throws IOException
      creates a Zip file to the given destination and with the given files
      Parameters:
      zipFileDestination -
      files -
      Throws:
      IOException
    • createZipFileInMemory

      public static ByteArrayOutputStream createZipFileInMemory(List<File> files) throws IOException
      Creates a Zip File containing the given Files and stores it in Memory
      Parameters:
      files -
      Returns:
      Throws:
      IOException
    • createZipFileInMemory

      public static ByteArrayOutputStream createZipFileInMemory(InputStream[] dataStreams, String[] entryName) throws IOException
      Creates a Zip File containing the given InputStreams and stores it in Memory.
      Parameters:
      dataStreams - An array of InputStreams representing the data to be added to the zip.
      Returns:
      A ByteArrayOutputStream containing the in-memory zip file.
      Throws:
      IOException - if something goes wrong.
    • extractZip

      public static Map<String,ByteArrayOutputStream> extractZip(InputStream zipInputStream) throws IOException
      Extracts files from a Zip file to the given destination directory.
      Parameters:
      zipInputStream - InputStream of the Zip file.
      Returns:
      Map where the key is the filename and the value is the corresponding File object.
      Throws:
      IOException