Package org.identityconnectors.common
Class IOUtil
java.lang.Object
org.identityconnectors.common.IOUtil
IO Utilities
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic longstatic longCalculates the CRC32 checksum of the specified file.static booleanCopies a file to a destination.static longcopyFile(InputStream fis, OutputStream fos) Copies one file to another.static voidRecursively delete all the files in a directory and the directory.static voidextractResourceToFile(Class<?> clazz, String path, File file) Extracts the resource to a file.static byte[]getResourceAsBytes(Class<?> clazz, String res) Get the resource as a byte array.static PropertiesgetResourceAsProperties(ClassLoader loader, String path) Loads the given resource as a properties object.static InputStreamgetResourceAsStream(Class<?> clazz, String res) Returns an input stream of the resource specified.static StringgetResourceAsString(Class<?> clazz, String res) Read the entire stream into a String and return it.static StringgetResourceAsString(Class<?> clazz, String res, Charset charset) Read the entire stream into a String and return it.static StringgetResourcePath(Class<?> c, String res) Get the path to a resource base on the package of given class.static byte[]Takes a 'InputStream' and returns a byte array.static PropertiesLoads the given file as a Properties file.static PropertiesloadPropertiesFile(String string) Attempt to load file based on a string base filename.static URLMake a URL from a directory and path.static voidquietClose(InputStream stream) Quietly closes the stream.static voidquietClose(OutputStream stream) Quietly closes the stream.static voidquietClose(Reader reader) Quietly closes the reader.static voidquietClose(Writer writer) Quietly closes the Writer.static StringreaderToString(Reader rdr) Takes a 'Reader' and returns the contents as a string.static byte[]readFileBytes(File file) Reads the given file as bytesstatic StringreadFileUTF8(File file) Reads the given file as UTF-8static byte[]readInputStreamBytes(InputStream is, boolean close) Reads an entire file and returns the bytes.static voidstorePropertiesFile(File f, Properties properties) Stores the given file as a Properties file.static voidUnjars the given file to the given directory.static voidwriteFileUTF8(File file, String contents) Write the contents of the string out to a file in UTF-8 format.
-
Field Details
-
UTF8
- See Also:
-
-
Method Details
-
quietClose
Quietly closes the reader. This avoids having to handle exceptions, and then inside of the exception handling have a try catch block to close the reader and catch anyIOExceptionwhich may be thrown and ignore it.- Parameters:
reader- - Reader to close
-
quietClose
Quietly closes the stream. This avoids having to handle exceptions, and then inside of the exception handling have a try catch block to close the stream and catch anyIOExceptionwhich may be thrown.- Parameters:
stream- - Stream to close
-
quietClose
Quietly closes the Writer. This avoids having to handle exceptions, and then inside of the exception handling have a try catch block to close the Writer and catch any ioexceptions which may be thrown.- Parameters:
writer- - Writer to close
-
quietClose
Quietly closes the stream. This avoids having to handle exceptions, and then inside of the exception handling have a try catch block to close the stream and catch any ioexceptions which may be thrown.- Parameters:
stream- - Stream to close
-
getResourcePath
Get the path to a resource base on the package of given class.- Parameters:
c- Class to get the package path too.res- Name of the resource to get the path of.- Returns:
- Returns the fully quilified path to a resource.
-
getResourceAsStream
Returns an input stream of the resource specified.- Returns:
- Returns an InputStream to the resource.
-
getResourceAsBytes
Get the resource as a byte array. -
getResourceAsString
Read the entire stream into a String and return it. -
getResourceAsString
Read the entire stream into a String and return it. -
inputStreamToBytes
Takes a 'InputStream' and returns a byte array. -
readerToString
Takes a 'Reader' and returns the contents as a string.- Parameters:
rdr- Producer for the string data.- Returns:
- Null if the 'Reader' is broken or empty otherwise the contents as a string.
-
copyFile
Copies a file to a destination.- Parameters:
src- The source must be a filedest- This can be a directory or a file.- Returns:
- True if succeeded otherwise false.
- Throws:
IOException
-
copyFile
Copies one file to another.NOTE: does not close streams.
- Returns:
- total bytes copied.
- Throws:
IOException
-
checksum
Calculates the CRC32 checksum of the specified file.- Parameters:
fileName- - the path to the file on which to calculate the checksum- Throws:
IOExceptionFileNotFoundException
-
checksum
- Throws:
IOExceptionFileNotFoundException
-
readInputStreamBytes
Reads an entire file and returns the bytes.- Parameters:
close- if true, close when finished reading.- Returns:
- file bytes.
- Throws:
IOException
-
delete
Recursively delete all the files in a directory and the directory.- Throws:
RuntimeException- iff there is file that can not be deleted.IOException
-
loadPropertiesFile
Loads the given file as a Properties file.- Throws:
IOException
-
storePropertiesFile
Stores the given file as a Properties file.- Throws:
IOException
-
getResourceAsProperties
public static Properties getResourceAsProperties(ClassLoader loader, String path) throws IOException Loads the given resource as a properties object.- Parameters:
loader- The class loaderpath- The path to the resource- Returns:
- The properties or null if not found
- Throws:
IOException- If an error occurs reading it
-
extractResourceToFile
Extracts the resource to a file.- Parameters:
clazz- The class, relative to which path is resolvedpath- The path to the resourcefile- The file to extract to- Throws:
IOException- If an error occurs reading it
-
unjar
Unjars the given file to the given directory. Does not close the JarFile when finished.- Parameters:
jarFile- The file to unjar.toDir- The directory to unjar to.- Throws:
IOException
-
readFileUTF8
Reads the given file as UTF-8- Parameters:
file- The file to read- Returns:
- The contents of the file
- Throws:
IOException- iff there is an issue reading the file.
-
readFileBytes
Reads the given file as bytes- Parameters:
file- The file to read- Returns:
- The contents of the file
- Throws:
IOException- iff there is an issue reading the file.
-
writeFileUTF8
Write the contents of the string out to a file in UTF-8 format.- Parameters:
file- the file to write to.contents- the contents of the file to write to.- Throws:
IOException- iff there is an issue writing the file.NullPointerException- iff the file parameter is null.
-
makeURL
Make a URL from a directory and path.- Parameters:
dir- directory to start from.path- file or path to create the url.- Returns:
- URL based on the parameter provided.
- Throws:
IOException- iff the URL create from the parameters does not specify a file.
-
loadPropertiesFile
Attempt to load file based on a string base filename.- Parameters:
string- represents the file.- Returns:
- a loaded properties file.
- Throws:
IOException- if there is an issue.
-