org.jppf.io
Class IOHelper

java.lang.Object
  extended by org.jppf.io.IOHelper

public final class IOHelper
extends Object

Collection of utility methods to create and manipulate IO objects.

Author:
Laurent Cohen

Method Summary
static DataLocation createDataLocationMemorySensitive(int size)
          Create a data location object based on a comparison of the available heap memory and the data location object size.
static File createTempFile(int size)
          Create a temporary file.
static boolean fitsInMemory(int size)
          Determines whether the data of the specified size would fit in memory.
static DataLocation readData(InputSource source)
          Read a provider or task data from an input source.
static void sendData(SocketWrapper socketWrapper, Object o, ObjectSerializer ser)
          Serialize an object and send it to the server.
static DataLocation serializeData(Object o, ObjectSerializer ser)
          Serialize an object and send it to the server.
static DataLocation serializeDataToFile(Object o, ObjectSerializer ser)
          Serialize an object and send it to the server.
static DataLocation serializeDataToMemory(Object o, ObjectSerializer ser)
          Serialize an object to a bugffer in memory.
static InputStream unwrapData(JPPFDataTransform transform, DataLocation source)
          Apply a JPPFDataTransform to the specified source and store the results in memory.
static InputStream unwrapDataToFile(JPPFDataTransform transform, DataLocation source)
          Apply a JPPFDataTransform to the specified source and store the results in a temporary file.
static Object unwrappedData(DataLocation dl, ObjectSerializer ser)
          Deserialize the specified data into an object.
static Object unwrappedData(SocketWrapper socketWrapper, ObjectSerializer ser)
          Deserialize the next object available via a network connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createDataLocationMemorySensitive

public static DataLocation createDataLocationMemorySensitive(int size)
                                                      throws Exception
Create a data location object based on a comparison of the available heap memory and the data location object size.

Parameters:
size - the requested size of the data location to create.
Returns:
a DataLocation object whose content may be stored in memory or on another medium, depending on the available memory.
Throws:
Exception - if an IO error occurs.

readData

public static DataLocation readData(InputSource source)
                             throws Exception
Read a provider or task data from an input source. The data may be stored in memory or on another medium depending on its size and the available memory.

Parameters:
source - the input source from which to read the data.
Returns:
A data location containing the data provider or task data.
Throws:
Exception - if an error occurs while deserializing.

createTempFile

public static File createTempFile(int size)
                           throws Exception
Create a temporary file.

Parameters:
size - the file size (for logging purposes only).
Returns:
the created File.
Throws:
Exception - if an IO error occurs.

fitsInMemory

public static boolean fitsInMemory(int size)
Determines whether the data of the specified size would fit in memory.

Parameters:
size - the data size to check.
Returns:
true if the data would fit in memory, false otherwise.

unwrappedData

public static Object unwrappedData(SocketWrapper socketWrapper,
                                   ObjectSerializer ser)
                            throws Exception
Deserialize the next object available via a network connection.

Parameters:
socketWrapper - the network connection used to read data.
ser - the object serializer to use.
Returns:
the transformed result as an object.
Throws:
Exception - if an error occurs while preparing the data.

unwrappedData

public static Object unwrappedData(DataLocation dl,
                                   ObjectSerializer ser)
                            throws Exception
Deserialize the specified data into an object.

Parameters:
dl - the data, stored in a memory-aware location.
ser - the object serializer to use.
Returns:
the transformed result as an object.
Throws:
Exception - if an error occurs while preparing the data.

unwrapData

public static InputStream unwrapData(JPPFDataTransform transform,
                                     DataLocation source)
                              throws Exception
Apply a JPPFDataTransform to the specified source and store the results in memory.

Parameters:
transform - the JPPFDataTransform to apply.
source - the source data to transform.
Returns:
the transformed data as an InputStream.
Throws:
Exception - if an error occurs while preparing the data.

unwrapDataToFile

public static InputStream unwrapDataToFile(JPPFDataTransform transform,
                                           DataLocation source)
                                    throws Exception
Apply a JPPFDataTransform to the specified source and store the results in a temporary file.

Parameters:
transform - the JPPFDataTransform to apply.
source - the source data to transform.
Returns:
the transformed data as a File.
Throws:
Exception - if an error occurs while preparing the data.

sendData

public static void sendData(SocketWrapper socketWrapper,
                            Object o,
                            ObjectSerializer ser)
                     throws Exception
Serialize an object and send it to the server.

Parameters:
socketWrapper - the socket client used to send data to the server.
o - the object to serialize.
ser - the object serializer.
Throws:
Exception - if any error occurs.

serializeData

public static DataLocation serializeData(Object o,
                                         ObjectSerializer ser)
                                  throws Exception
Serialize an object and send it to the server.

Parameters:
o - the object to serialize.
ser - the object serializer.
Returns:
a DataLocation instance.
Throws:
Exception - if any error occurs.

serializeDataToMemory

public static DataLocation serializeDataToMemory(Object o,
                                                 ObjectSerializer ser)
                                          throws Exception
Serialize an object to a bugffer in memory.

Parameters:
o - the object to serialize.
ser - the object serializer.
Returns:
an instance of MultipleBuffersOutputStream.
Throws:
Exception - if any error occurs.

serializeDataToFile

public static DataLocation serializeDataToFile(Object o,
                                               ObjectSerializer ser)
                                        throws Exception
Serialize an object and send it to the server.

Parameters:
o - the object to serialize.
ser - the object serializer.
Returns:
an instance of FileDataLocation.
Throws:
Exception - if any error occurs.


Copyright © 2005-2010 JPPF Team.