Class IOUtil
java.lang.Object
de.uni_trier.wi2.procake.utils.io.IOUtil
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clears the content of the default directory.static void
Clears the content of the given directory.static void
createDirectories
(String path) Creates all parent directories.static void
createZipFile
(String zipFileDestination, List<File> files) creates a Zip file to the given destination and with the given filesstatic ByteArrayOutputStream
createZipFileInMemory
(InputStream[] dataStreams, String[] entryName) Creates a Zip File containing the given InputStreams and stores it in Memory.static ByteArrayOutputStream
createZipFileInMemory
(List<File> files) Creates a Zip File containing the given Files and stores it in Memorystatic void
deleteFolder
(File folder) Deletes a given folder.static Map<String,
ByteArrayOutputStream> extractZip
(InputStream zipInputStream) Extracts files from a Zip file to the given destination directory.static InputStream
getInputStream
(String path) Returns a file input stream for the specified path.static boolean
Checks whether the default directory is empty.static <T> T
readFile
(InputStream inputStream, Class<T> clazz) Reads a file with a suitable reader from the specified input stream.static <T> T
readFile
(InputStream inputStream, String readerName) Reads a file with a given reader from the specified input stream.static <T> T
Reads a file with a suitable reader from the specified path.static <T> T
Reads a file with a given reader from the specified path.static <T> T
readString
(String xmlString, Class<T> clazz) Reads an XML string with a suitable reader.static <T> T
readString
(String objXML, String readerName) Reads a file with a given reader from a given String.static void
Extracts a zip file specified by the zipFilePath to a directory specified by destDirectory (will be created if it does not exist).static String
Writes a given object with a suitable writer to the local file system at the specified path.static String
Writes a given object with a given writer to the local file system at the specified path.static String
writeFileToDefaultDir
(Object object, String relativePath) Writes a given object with a suitable writer to the local file system to the default directory.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.static String
writeString
(Object object) Writes a given object with a suitable writer to a String.static String
writeString
(Object object, String writerName) Writes a given object with a given writer to a String.static void
writeStringToFile
(Object obj, String path)
-
Constructor Details
-
IOUtil
public IOUtil()
-
-
Method Details
-
writeFile
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
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
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
Creates all parent directories.- Parameters:
path
- the path
-
writeStringToFile
-
writeFileToDefaultDir
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
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 forreaderName
- the name of the reader to use- Returns:
- object parsed from the file at the specified path
-
readFile
Reads a file with a given reader from the specified input stream.- Parameters:
inputStream
- the input stream to read fromreaderName
- the name of the reader to use- Returns:
- object parsed from the file at the specified input stream
-
readFile
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 pathclazz
- class of the object to find a suitable reader- Returns:
- object parsed from the file at the specified path
-
readFile
Reads a file with a suitable reader from the specified input stream.- Parameters:
inputStream
- input streamclazz
- class of the object to find a suitable reader- Returns:
- object parsed from the file at the specified input stream
-
readString
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
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 objectreaderName
-- Returns:
- Object parsed from the String
-
writeString
Writes a given object with a suitable writer to a String.- Parameters:
object
-- Returns:
- string representation of the given object
-
writeString
Writes a given object with a given writer to a String.- Parameters:
object
-writerName
-- Returns:
- string representation of the given object
-
getInputStream
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
Clears the content of the given directory. -
deleteFolder
Deletes a given folder. -
unzip
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
creates a Zip file to the given destination and with the given files- Parameters:
zipFileDestination
-files
-- Throws:
IOException
-
createZipFileInMemory
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
-