public final class IOUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static Properties |
createPropertiesFromResource(Class<?> classObj,
String resourceName)
Creates a
Properties objects and loads the data in the given
resource, using the given class' getResourceAsStream method. |
static InputStream |
getResourceAsStream(String name)
Finds a resource with a given name, using this class' class loader.
|
static InputStream |
getResourceAsStream(String name,
Class<?> cls)
Finds a resource with a given name using the class loader of the
specified class.
|
static String |
getUserInput(String prompt) |
static Properties |
loadPropertiesFromResource(Class<?> cls,
String resource) |
static Properties[] |
loadPropertiesFromResources(Class<?> cls,
String[] resources) |
static void |
readPropertiesFromResource(Properties properties,
Class<?> classObj,
String resourceName)
Loads properties from the given resource into the given properties
object.
|
static List<String> |
readResourceAsLines(Class<?> classObj,
String resourceName)
Reads everything from a textual resource as lines using the default
character set.
|
static String |
readResourceAsString(Class<?> classObj,
String resourceName)
Reads everything from the given resource into a
String using
the default character set. |
static File |
resourceToFile(String resourceName,
String filePrefix,
String fileSuffix)
Converts a resource into a temporary file that can be read by objects
that look up files by name.
|
public static String readResourceAsString(Class<?> classObj, String resourceName) throws IOException
String using
the default character set.classObj - the Class from which
Class.getResourceAsStream is invoked. If null,
will use IOUtil.class.resourceName - a resource name String.String, or null if
resourceName is null.IOException - if the resource cannot be found or if there is an
error reading from it.public static List<String> readResourceAsLines(Class<?> classObj, String resourceName) throws IOException
classObj - the Class from which
Class.getResourceAsStream is invoked. If null,
will use IOUtil.class.resourceName - a resource name String.String, or null if
resourceName is null.IOException - if the resource cannot be found or if there is an
error reading from it.public static void readPropertiesFromResource(Properties properties, Class<?> classObj, String resourceName) throws IOException
properties - the Properties, using the given class'
getResourceAsStream method.classObj - the Class whose getResourceAsStream
method is called, cannot be null.resourceName - a resource String, visible * * from
classObj's class loader. If null, this method
does nothing.IOException - if an error occurred reading the resource.public static Properties createPropertiesFromResource(Class<?> classObj, String resourceName) throws IOException
Properties objects and loads the data in the given
resource, using the given class' getResourceAsStream method.classObj - the Class whose getResourceAsStream
method is called, cannot be null.resourceName - a resource String, visible * * from
classObj's class loader. If null, this methods
returns an empty Properties object.Properties object.IOExceptionpublic static String getUserInput(String prompt) throws IOException
IOExceptionpublic static Properties loadPropertiesFromResource(Class<?> cls, String resource) throws IOException
IOExceptionpublic static Properties[] loadPropertiesFromResources(Class<?> cls, String[] resources) throws IOException
IOExceptionpublic static InputStream getResourceAsStream(String name) throws IOException
Class.getResourceAsStream(java.lang.String), except it throws an
IllegalArgumentException if the specified resource name is
null, and it throws an IOException if no resource
with the specified name is found.name - name String of the desired resource. Cannot be
null.InputStream.IOException - if no resource with this name is found.public static InputStream getResourceAsStream(String name, Class<?> cls) throws IOException
Class.getResourceAsStream(java.lang.String), except it throws an
IllegalArgumentException if the specified resource name is
null, and it throws an IOException if no resource
with the specified name is found.name - name String of the desired resource. Cannot be
null.cls - the Class whose loader to use.InputStream.IOException - if no resource with this name is found.public static File resourceToFile(String resourceName, String filePrefix, String fileSuffix) throws IOException
resourceName - the resource to convert. Cannot be null.filePrefix - the prefix of the temporary file. Cannot be
null.fileSuffix - the suffix of the temporary file.File.IOException - if an error occurs while writing the contents of the
resource to the temporary file.Copyright © 2012–2017 Emory University. All rights reserved.