Class WritableFactory


  • public class WritableFactory
    extends Object
    • Method Detail

      • getInstance

        public static WritableFactory getInstance()
        Returns:
        Singleton WritableFactory instance
      • registerWritableType

        public void registerWritableType​(short writableTypeKey,
                                         @NonNull
                                         @NonNull Class<? extends Writable> writableClass)
        Register a writable class with a specific key (as a short). Note that key values must be unique for each type of Writable, as they are used as type information in certain types of serialisation. Consequently, an exception will be thrown If the key value is not unique or is already assigned.
        Note that in general, this method needs to only be used for custom Writable types; Care should be taken to ensure that the given key does not change once assigned.
        Parameters:
        writableTypeKey - Key for the Writable
        writableClass - Class for the given key. Must have a no-arg constructor
      • newWritable

        public Writable newWritable​(short writableTypeKey)
        Create a new writable instance (using reflection) given the specified key
        Parameters:
        writableTypeKey - Key to create a new writable instance for
        Returns:
        A new (empty/default) Writable instance
      • writeWithType

        public void writeWithType​(Writable w,
                                  DataOutput dataOutput)
                           throws IOException
        A convenience method for writing a given Writable object to a DataOutput. The key is 1st written (a single short) followed by the value from writable.
        Parameters:
        w - Writable value
        dataOutput - DataOutput to write both key and value to
        Throws:
        IOException - If an error occurs during writing to the DataOutput