Package org.exoplatform.commons.utils
Class IOUtil
- java.lang.Object
-
- org.exoplatform.commons.utils.IOUtil
-
public class IOUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description IOUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static 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[]getStreamContentAsBytes(InputStream is)Reads a stream until its end and returns its content as a byte array.static StringgetStreamContentAsString(InputStream is)Returns the content of the specified stream as a string using theUTF-8charset.static byte[]serialize(Object obj)Deprecated.
-
-
-
Method Detail
-
getFileContentAsString
public static String getFileContentAsString(File file) throws IOException, IllegalArgumentException
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
public static String getResourceAsString(String resource) throws IOException
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
public static byte[] getResourceAsBytes(String resource) throws IOException
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 public static byte[] serialize(Object obj) throws Exception
Deprecated.- Throws:
Exception
-
deserialize
@Deprecated public static Object deserialize(byte[] bytes) throws Exception
Deprecated.- Throws:
Exception
-
getFileContenntAsString
@Deprecated public static String getFileContenntAsString(File file) throws Exception
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 public static String getFileContenntAsString(String fileName) throws Exception
Deprecated.UsegetFileContentAsString(String)instead.- Throws:
Exception
-
-