Package org.jppf.io
Class IOHelper
java.lang.Object
org.jppf.io.IOHelper
Collection of utility methods to create and manipulate IO objects.
- Author:
- Laurent Cohen
-
Method Summary
Modifier and TypeMethodDescriptionstatic DataLocationcreateDataLocationMemorySensitive(int size) Create a data location object based on a comparison of the available heap memory and the data location object size.static FilecreateTempFile(int size) Create a temporary file.static booleanfitsInMemory(int size) Determines whether the data of the specified size would fit in memory.static ObjectSerializerstatic DataLocationreadData(InputSource source) Read a provider or task data from an input source.static DataLocationreadData(InputSource source, int size) Read a provider or task data from an input source with a known data size.static voidsendData(SocketWrapper socketWrapper, Object o, ObjectSerializer ser) Serialize an object and send it to the server.static voidsendNullData(SocketWrapper socketWrapper) Send a null object to the server.static DataLocationSerialize an object into aDataLocation.static DataLocationserializeData(Object o, ObjectSerializer ser) Serialize an object into aDataLocation.static DataLocationSerialize an object and send it to the server.static DataLocationSerialize an object to a buffer in memory.static ObjectunwrappedData(SocketWrapper socketWrapper, ObjectSerializer ser) Deserialize the next object available via a network connection.static ObjectDeserialize the specified data into an object, using a default serializer.static ObjectunwrappedData(DataLocation dl, ObjectSerializer ser) Deserialize the specified data into an object.static voidwriteData(DataLocation data, OutputDestination destination) Write the specified data to the specified destination.
-
Method Details
-
createDataLocationMemorySensitive
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
DataLocationobject whose content may be stored in memory or on another medium, depending on the available memory. - Throws:
Exception- if an IO error occurs.
-
readData
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 reading the data.
-
readData
Read a provider or task data from an input source with a known data size. 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.size- the size of the data to read.- Returns:
- A data location containing the data provider or task data.
- Throws:
Exception- if an error occurs while reading the data.
-
writeData
Write the specified data to the specified destination.- Parameters:
data- the data to write.destination- tyhe destination to write to.- Throws:
Exception- if any error occurs.
-
createTempFile
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
Deserialize the specified data into an object, using a default serializer.- Parameters:
dl- the data, stored in a memory-aware location.- Returns:
- the transformed result as an object.
- Throws:
Exception- if an error occurs while preparing the data.
-
unwrappedData
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.
-
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.
-
sendNullData
Send a null object to the server.- Parameters:
socketWrapper- the socket client used to send data to the server.- Throws:
Exception- if any error occurs.
-
serializeData
Serialize an object into aDataLocation.- Parameters:
o- the object to serialize.- Returns:
- a
DataLocationinstance. - Throws:
Exception- if any error occurs.
-
serializeData
Serialize an object into aDataLocation.- Parameters:
o- the object to serialize.ser- the object serializer.- Returns:
- a
DataLocationinstance. - Throws:
Exception- if any error occurs.
-
serializeDataToMemory
Serialize an object to a buffer in memory.- Parameters:
o- the object to serialize.ser- the object serializer.- Returns:
- an instance of
MultipleBuffersOutputStream. - Throws:
Exception- if any error occurs.
-
serializeDataToFile
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.
-
getDefaultserializer
- Returns:
- the default serilaizer to use when none is specified.
-