Class IOUtil
- java.lang.Object
-
- de.uni_trier.wi2.procake.utils.io.IOUtil
-
public class IOUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description IOUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclearDefaultDir()Clears the content of the default directory.static voidclearDir(File folder)Clears the content of the given directory.static InputStreamgetInputStream(String path)Returns a file input stream for the specified path.static booleanisEmptyDefaultDir()Checks whether the default directory is empty.static <T> TreadFile(InputStream inputStream, Class<T> clazz)Reads a file with a suitable reader from the specified input stream.static <T> TreadFile(InputStream inputStream, String readerName)Reads a file with a given reader from the specified input stream.static <T> TreadFile(String path, Class<T> clazz)Reads a file with a suitable reader from the specified path.static <T> TreadFile(String path, String readerName)Reads a file with a given reader from the specified path.static <T> TreadString(String xmlString, Class<T> clazz)Reads an XML string with a suitable reader.static <T> TreadString(String objXML, String readerName)Reads a file with a given reader from a given String.static voidunzip(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).static StringwriteFile(Object object, String absolutePath)Writes a given object with a suitable writer to the local file system at the specified path.static StringwriteFile(Object object, String absolutePath, String writerName)Writes a given object with a given writer to the local file system at the specified path.static StringwriteFileToDefaultDir(Object object, String relativePath)Writes a given object with a suitable writer to the local file system to the default directory.static StringwriteFileToDefaultDir(Object object, String relativePath, String writerName)Writes a given object with a given writer to the local file system to the default directory.static StringwriteString(Object object)Writes a given object with a suitable writer to a String.static StringwriteString(Object object, String writerName)Writes a given object with a given writer to a String.
-
-
-
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 pathclazz- 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 streamclazz- 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 objectreaderName-- 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-
-
-