Package uk.ac.ebi.utils.opt.io
Class IOUtils
java.lang.Object
uk.ac.ebi.utils.opt.io.IOUtils
Miscellanea of small IO utilities.
TODO: complete the migration to unchecked exceptions.
- date
- July 29, 2007, 1:03 PM
- Author:
- brandizi
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
A wrapper togetHash(InputStream, String)
that opens a file.static String
getHash
(InputStream is, String algorithm) Reads the input stream and returns an hash for it, based on the algorithm passed as parameter. algorithm is passed toMessageDigest
static String
Hashes a string, usinggetHash(InputStream, String)
.static String
A wrapper of#getHash(InputStream, File)
that uses the MD5 algorithm.static String
getMD5
(InputStream is) A wrapper ofgetHash(InputStream, String)
that uses the MD5 algorithm.static String
A wrapper forgetHash(String, String)
that uses MD5.static Reader
openResourceReader
(Class<?> clazz, String path) Defaults to "UTF-8"static Reader
openResourceReader
(Class<?> clazz, String path, Charset charset) Facility to get a reader from a resource, usesResources.getResource(Class, String)
andURL.openStream()
.static Reader
openResourceReader
(String path) Defaults to UTF-8static Reader
openResourceReader
(String path, Charset charset) static String
Defaults to UTF-8static String
static String
Opens an input stream from a file path.static String[]
Defaults to any file, ignoreMissingDir = false, UTF-8static String[]
Defaults to any file, UTF-8static String[]
Defaults to any filestatic String[]
readFiles
(String dirPath, FilenameFilter filter) Defaults to missingDir = false, `UTF-8`.static String[]
readFiles
(String dirPath, FilenameFilter filter, boolean ignoreMissingDir) Defaults to `UTF-8`.static String[]
readFiles
(String dirPath, FilenameFilter filter, boolean ignoreMissingDir, Charset charSet) InvokesreadFile(String, Charset)
upon all the files in a directory and return an array of file contents.static String[]
readFiles
(String dirPath, FilenameFilter filter, Charset charSet) Defaults to missingDir = falsestatic String[]
Defaults to any file, ignoreMissingDir = falsestatic String
readResource
(Class<?> clazz, String path) WARNING: after 5.0 this uses UTF-8 as default and not the system default!static String
readResource
(Class<?> clazz, String path, Charset charset) Facility to read a resource from the class loader associated to a class.static String
readResource
(ClassLoader classLoader, String path) Defaults to UTF-8static String
readResource
(ClassLoader classLoader, String path, Charset charset) Facility to read a resource from a class loader.static String
readResource
(String path) Defaults to UTF-8static String
readResource
(String path, Charset charset) Uses the class loader in the current thread, or the one inResources
.static URI
Creates a URI and intercepts URISyntaxException, throwing IllegalArgumentException if such an exception occurs.static URL
static void
Defaults to UTF8, append = falsestatic void
Defaults to UTF8static void
Writes the string to the file and then closes it
-
Method Details
-
readFile
- Throws:
UncheckedIOException
- See Also:
-
readFile
Opens an input stream from a file path.- Throws:
UncheckedIOException
-
readFile
Defaults to UTF-8- Throws:
UncheckedIOException
-
readFiles
public static String[] readFiles(String dirPath, FilenameFilter filter, boolean ignoreMissingDir, Charset charSet) throws UncheckedFileNotFoundException, UncheckedIOException InvokesreadFile(String, Charset)
upon all the files in a directory and return an array of file contents. -
readFiles
public static String[] readFiles(String dirPath, FilenameFilter filter, Charset charSet) throws UncheckedIOException Defaults to missingDir = false- Throws:
UncheckedIOException
-
readFiles
public static String[] readFiles(String dirPath, FilenameFilter filter, boolean ignoreMissingDir) throws UncheckedIOException Defaults to `UTF-8`.- Throws:
UncheckedIOException
-
readFiles
Defaults to missingDir = false, `UTF-8`.- Throws:
UncheckedIOException
-
readFiles
public static String[] readFiles(String dirPath, boolean ignoreMissingDir, Charset charSet) throws UncheckedIOException Defaults to any file- Throws:
UncheckedIOException
-
readFiles
public static String[] readFiles(String dirPath, boolean ignoreMissingDir) throws UncheckedIOException Defaults to any file, UTF-8- Throws:
UncheckedIOException
-
readFiles
Defaults to any file, ignoreMissingDir = false- Throws:
UncheckedIOException
-
readFiles
Defaults to any file, ignoreMissingDir = false, UTF-8- Throws:
UncheckedIOException
-
openResourceReader
public static Reader openResourceReader(Class<?> clazz, String path, Charset charset) throws IOException Facility to get a reader from a resource, usesResources.getResource(Class, String)
andURL.openStream()
.- Throws:
IOException
-
openResourceReader
Defaults to "UTF-8"- Throws:
IOException
-
openResourceReader
- Throws:
IOException
-
openResourceReader
Defaults to UTF-8- Throws:
IOException
-
readResource
Facility to read a resource from the class loader associated to a class.- Throws:
IOException
-
readResource
WARNING: after 5.0 this uses UTF-8 as default and not the system default!- Throws:
IOException
-
readResource
Uses the class loader in the current thread, or the one inResources
.- Throws:
IOException
-
readResource
Defaults to UTF-8- Throws:
IOException
-
readResource
public static String readResource(ClassLoader classLoader, String path, Charset charset) throws IOException Facility to read a resource from a class loader.- Throws:
IOException
-
readResource
Defaults to UTF-8- Throws:
IOException
-
writeFile
public static void writeFile(String path, String string, Charset charSet, boolean append) throws IOException Writes the string to the file and then closes it- Throws:
IOException
-
writeFile
Defaults to UTF8- Throws:
IOException
-
writeFile
Defaults to UTF8, append = false- Throws:
IOException
-
getHash
public static String getHash(InputStream is, String algorithm) throws IOException, NoSuchAlgorithmException Reads the input stream and returns an hash for it, based on the algorithm passed as parameter. algorithm is passed toMessageDigest
- Throws:
IOException
NoSuchAlgorithmException
-
getHash
A wrapper togetHash(InputStream, String)
that opens a file.- Throws:
IOException
NoSuchAlgorithmException
-
getHash
Hashes a string, usinggetHash(InputStream, String)
.- Throws:
NoSuchAlgorithmException
-
getMD5
A wrapper ofgetHash(InputStream, String)
that uses the MD5 algorithm.- Throws:
IOException
-
getMD5
A wrapper of#getHash(InputStream, File)
that uses the MD5 algorithm.- Throws:
IOException
-
getMD5
A wrapper forgetHash(String, String)
that uses MD5. -
uri
Creates a URI and intercepts URISyntaxException, throwing IllegalArgumentException if such an exception occurs. I've created this method because it's often very annoying to have a checked exception here. -
url
- See Also:
-