Package org.jppf.io

Class IOHelper

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

public final class IOHelper extends Object
Collection of utility methods to create and manipulate IO objects.
Author:
Laurent Cohen
  • Method Details

    • 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 reading the data.
    • readData

      public static DataLocation readData(InputSource source, int size) throws Exception
      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

      public static void writeData(DataLocation data, OutputDestination destination) throws Exception
      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

      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) throws Exception
      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

      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.
    • 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

      public static void sendNullData(SocketWrapper socketWrapper) throws Exception
      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

      public static DataLocation serializeData(Object o) throws Exception
      Serialize an object into a DataLocation.
      Parameters:
      o - the object to serialize.
      Returns:
      a DataLocation instance.
      Throws:
      Exception - if any error occurs.
    • serializeData

      public static DataLocation serializeData(Object o, ObjectSerializer ser) throws Exception
      Serialize an object into a DataLocation.
      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 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

      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.
    • getDefaultserializer

      public static ObjectSerializer getDefaultserializer()
      Returns:
      the default serilaizer to use when none is specified.