org.exoplatform.commons.utils
Class IOUtil

java.lang.Object
  extended by org.exoplatform.commons.utils.IOUtil

public class IOUtil
extends java.lang.Object


Constructor Summary
IOUtil()
           
 
Method Summary
static java.lang.Object deserialize(byte[] bytes)
          Deprecated. 
static java.lang.String getFileContenntAsString(java.io.File file)
          Deprecated. 
static java.lang.String getFileContenntAsString(java.io.File file, java.lang.String encoding)
          Deprecated. 
static java.lang.String getFileContenntAsString(java.lang.String fileName)
          Deprecated. 
static java.lang.String getFileContenntAsString(java.lang.String fileName, java.lang.String encoding)
          Deprecated. 
static byte[] getFileContentAsBytes(java.lang.String fileName)
          Returns the content of the file specified by its name as a byte array.
static java.lang.String getFileContentAsString(java.io.File file)
          Returns the content of the specified file as a string using the UTF-8 charset.
static java.lang.String getFileContentAsString(java.io.File file, java.lang.String charset)
          Returns the content of the specified file as a string using the specified charset.
static java.lang.String getFileContentAsString(java.lang.String fileName)
          Returns the content of the specified file as a string using the UTF-8 charset.
static java.lang.String getFileContentAsString(java.lang.String fileName, java.lang.String charset)
          Returns the content of the specified file as a string using the specified charset.
static byte[] getResourceAsBytes(java.lang.String resource)
          Get a resource from the thread context classloader and returns its content as a byte array.
static java.lang.String getResourceAsString(java.lang.String resource)
          Get a resource from the thread context classloader and returns its content as a string.
static byte[] getStreamContentAsBytes(java.io.InputStream is)
          Reads a stream until its end and returns its content as a byte array.
static java.lang.String getStreamContentAsString(java.io.InputStream is)
          Returns the content of the specified stream as a string using the UTF-8 charset.
static byte[] serialize(java.lang.Object obj)
          Deprecated. 
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOUtil

public IOUtil()
Method Detail

getFileContentAsString

public static java.lang.String getFileContentAsString(java.io.File file)
                                               throws java.io.IOException,
                                                      java.lang.NullPointerException
Returns the content of the specified file as a string using the UTF-8 charset.

Parameters:
file - the file
Returns:
the content
Throws:
java.io.IOException - any io exception
java.lang.NullPointerException - if any argument is null

getFileContentAsString

public static java.lang.String getFileContentAsString(java.io.File file,
                                                      java.lang.String charset)
                                               throws java.io.IOException,
                                                      java.lang.NullPointerException
Returns the content of the specified file as a string using the specified charset.

Parameters:
file - the file
charset - the charset
Returns:
the content
Throws:
java.io.IOException - any io exception
java.lang.NullPointerException - if any argument is null

getFileContentAsString

public static java.lang.String getFileContentAsString(java.lang.String fileName,
                                                      java.lang.String charset)
                                               throws java.io.IOException,
                                                      java.lang.NullPointerException
Returns the content of the specified file as a string using the specified charset.

Parameters:
fileName - the file name
charset - the charset
Returns:
the content
Throws:
java.io.IOException - any io exception
java.lang.NullPointerException - if any argument is null

getFileContentAsString

public static java.lang.String getFileContentAsString(java.lang.String fileName)
                                               throws java.io.IOException,
                                                      java.lang.NullPointerException
Returns the content of the specified file as a string using the UTF-8 charset.

Parameters:
fileName - the file name
Returns:
the content
Throws:
java.io.IOException - any io exception
java.lang.NullPointerException - if any argument is null

getStreamContentAsString

public static java.lang.String getStreamContentAsString(java.io.InputStream is)
                                                 throws java.io.IOException,
                                                        java.lang.NullPointerException
Returns the content of the specified stream as a string using the UTF-8 charset.

Parameters:
is - the stream
Returns:
the content
Throws:
java.io.IOException - any io exception
java.lang.NullPointerException - if the specified stream is null

getFileContentAsBytes

public static byte[] getFileContentAsBytes(java.lang.String fileName)
                                    throws java.io.IOException,
                                           java.lang.NullPointerException
Returns the content of the file specified by its name as a byte array.

Parameters:
fileName - the file name
Returns:
the content
Throws:
java.io.IOException - any io exception
java.lang.NullPointerException - if the specified file name is null

getStreamContentAsBytes

public static byte[] getStreamContentAsBytes(java.io.InputStream is)
                                      throws java.io.IOException,
                                             java.lang.NullPointerException
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:
java.io.IOException - if any IOException occurs during a read
java.lang.NullPointerException - if the provided input stream is null

getResourceAsString

public static java.lang.String getResourceAsString(java.lang.String resource)
                                            throws java.io.IOException
Get a resource from the thread context classloader and returns its content as a string. The resource is obtained by calling the method ClassLoader.getResource(String) on the context classloader associated with the current thread of execution. The charset used for encoding the resource as a string is UTF-8.

Parameters:
resource - the resource name
Returns:
the resource content
Throws:
java.lang.NullPointerException - if the specified argument is null or the loaded resource does not exist
java.io.IOException - thrown by accessing the resource

getResourceAsBytes

public static byte[] getResourceAsBytes(java.lang.String resource)
                                 throws java.io.IOException
Get a resource from the thread context classloader and returns its content as a byte array. The resource is obtained by calling the method ClassLoader.getResource(String) on the context classloader associated with the current thread of execution.

Parameters:
resource - the resource name
Returns:
the resource content
Throws:
java.lang.NullPointerException - if the specified argument is null or the loaded resource does not exist
java.io.IOException - thrown by accessing the resource

serialize

@Deprecated
public static byte[] serialize(java.lang.Object obj)
                        throws java.lang.Exception
Deprecated. 

Throws:
java.lang.Exception

deserialize

@Deprecated
public static java.lang.Object deserialize(byte[] bytes)
                                    throws java.lang.Exception
Deprecated. 

Throws:
java.lang.Exception

getFileContenntAsString

@Deprecated
public static java.lang.String getFileContenntAsString(java.io.File file)
                                                throws java.lang.Exception
Deprecated. 

Use getFileContentAsString(File) instead.

Throws:
java.lang.Exception

getFileContenntAsString

@Deprecated
public static java.lang.String getFileContenntAsString(java.io.File file,
                                                                  java.lang.String encoding)
                                                throws java.lang.Exception
Deprecated. 

Use getFileContentAsString(File,String) instead.

Throws:
java.lang.Exception

getFileContenntAsString

@Deprecated
public static java.lang.String getFileContenntAsString(java.lang.String fileName,
                                                                  java.lang.String encoding)
                                                throws java.lang.Exception
Deprecated. 

Use getFileContentAsString(String,String) instead.

Throws:
java.lang.Exception

getFileContenntAsString

@Deprecated
public static java.lang.String getFileContenntAsString(java.lang.String fileName)
                                                throws java.lang.Exception
Deprecated. 

Use getFileContentAsString(String) instead.

Throws:
java.lang.Exception


Copyright © 2010 eXo Platform SAS. All Rights Reserved.