Package org.exoplatform.commons.utils
Class IOUtil
java.lang.Object
org.exoplatform.commons.utils.IOUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Objectdeserialize(byte[] bytes) Deprecated.static StringgetFileContenntAsString(File file) Deprecated.static StringgetFileContenntAsString(File file, String encoding) Deprecated.static StringgetFileContenntAsString(String fileName) Deprecated.static StringgetFileContenntAsString(String fileName, String encoding) Deprecated.static byte[]getFileContentAsBytes(String fileName) Returns the content of the file specified by its name as a byte array.static StringgetFileContentAsString(File file) Returns the content of the specified file as a string using theUTF-8charset.static StringgetFileContentAsString(File file, String charset) Returns the content of the specified file as a string using the specified charset.static StringgetFileContentAsString(String fileName) Returns the content of the specified file as a string using theUTF-8charset.static StringgetFileContentAsString(String fileName, String charset) Returns the content of the specified file as a string using the specified charset.static byte[]getResourceAsBytes(String resource) Get a resource from the thread context classloader and returns its content as a byte array.static StringgetResourceAsString(String resource) Get a resource from the thread context classloader and returns its content as a string.static byte[]Reads a stream until its end and returns its content as a byte array.static StringReturns the content of the specified stream as a string using theUTF-8charset.static byte[]Deprecated.
-
Constructor Details
-
IOUtil
public IOUtil()
-
-
Method Details
-
getFileContentAsString
Returns the content of the specified file as a string using theUTF-8charset.- Parameters:
file- the file- Returns:
- the content
- Throws:
IOException- any io exceptionIllegalArgumentException- if any argument is null
-
getFileContentAsString
public static String getFileContentAsString(File file, String charset) throws IOException, IllegalArgumentException Returns the content of the specified file as a string using the specified charset.- Parameters:
file- the filecharset- the charset- Returns:
- the content
- Throws:
IOException- any io exceptionIllegalArgumentException- if any argument is null
-
getFileContentAsString
public static String getFileContentAsString(String fileName, String charset) throws IOException, IllegalArgumentException Returns the content of the specified file as a string using the specified charset.- Parameters:
fileName- the file namecharset- the charset- Returns:
- the content
- Throws:
IOException- any io exceptionIllegalArgumentException- if any argument is null
-
getFileContentAsString
public static String getFileContentAsString(String fileName) throws IOException, IllegalArgumentException Returns the content of the specified file as a string using theUTF-8charset.- Parameters:
fileName- the file name- Returns:
- the content
- Throws:
IOException- any io exceptionIllegalArgumentException- if any argument is null
-
getStreamContentAsString
public static String getStreamContentAsString(InputStream is) throws IOException, IllegalArgumentException Returns the content of the specified stream as a string using theUTF-8charset.- Parameters:
is- the stream- Returns:
- the content
- Throws:
IOException- any io exceptionIllegalArgumentException- if the specified stream is null
-
getFileContentAsBytes
public static byte[] getFileContentAsBytes(String fileName) throws IOException, IllegalArgumentException Returns the content of the file specified by its name as a byte array.- Parameters:
fileName- the file name- Returns:
- the content
- Throws:
IOException- any io exceptionIllegalArgumentException- if the specified file name is null
-
getStreamContentAsBytes
public static byte[] getStreamContentAsBytes(InputStream is) throws IOException, IllegalArgumentException Reads a stream until its end and returns its content as a byte array. The provided stream will be closed by this method. Any runtime exception thrown when the stream is closed will be ignored and not rethrown.- Parameters:
is- the input stream- Returns:
- the data read from the input stream its end
- Throws:
IOException- if any IOException occurs during a readIllegalArgumentException- if the provided input stream is null
-
getResourceAsString
Get a resource from the thread context classloader and returns its content as a string. The resource is obtained by calling the methodClassLoader.getResource(String)on the context classloader associated with the current thread of execution. The charset used for encoding the resource as a string isUTF-8.- Parameters:
resource- the resource name- Returns:
- the resource content
- Throws:
IllegalArgumentException- if the specified argument is null or the loaded resource does not existIOException- thrown by accessing the resource
-
getResourceAsBytes
Get a resource from the thread context classloader and returns its content as a byte array. The resource is obtained by calling the methodClassLoader.getResource(String)on the context classloader associated with the current thread of execution.- Parameters:
resource- the resource name- Returns:
- the resource content
- Throws:
IllegalArgumentException- if the specified argument is null or the loaded resource does not existIOException- thrown by accessing the resource
-
serialize
Deprecated.- Throws:
Exception
-
deserialize
Deprecated.- Throws:
Exception
-
getFileContenntAsString
Deprecated.UsegetFileContentAsString(File)instead.- Throws:
Exception
-
getFileContenntAsString
@Deprecated public static String getFileContenntAsString(File file, String encoding) throws Exception Deprecated.UsegetFileContentAsString(File,String)instead.- Throws:
Exception
-
getFileContenntAsString
@Deprecated public static String getFileContenntAsString(String fileName, String encoding) throws Exception Deprecated.UsegetFileContentAsString(String,String)instead.- Throws:
Exception
-
getFileContenntAsString
Deprecated.UsegetFileContentAsString(String)instead.- Throws:
Exception
-