Class AvroItemWriter<T>

All Implemented Interfaces:
ItemStream, ItemStreamWriter<T>, ItemWriter<T>

public class AvroItemWriter<T> extends AbstractItemStreamItemWriter<T>
An ItemWriter that serializes data to an WritableResource using Avro.

This does not support restart on failure.

This writer is not thread-safe.

Since:
4.2
Author:
David Turanski, Mahmoud Ben Hassine
  • Constructor Details

    • AvroItemWriter

      public AvroItemWriter(org.springframework.core.io.WritableResource resource, org.springframework.core.io.Resource schema, Class<T> clazz)
      Parameters:
      resource - a WritableResource to which the objects will be serialized.
      schema - a Resource containing the Avro schema.
      clazz - the data type to be serialized.
    • AvroItemWriter

      public AvroItemWriter(org.springframework.core.io.WritableResource resource, Class<T> clazz)
      This constructor will create an ItemWriter that does not embedded Avro schema.
      Parameters:
      resource - a WritableResource to which the objects will be serialized.
      clazz - the data type to be serialized.
  • Method Details

    • write

      public void write(Chunk<? extends T> items) throws Exception
      Description copied from interface: ItemWriter
      Process the supplied data element. Will not be called with any null items in normal operation.
      Parameters:
      items - of items to be written. Must not be null.
      Throws:
      Exception - if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.
    • open

      public void open(ExecutionContext executionContext)
      Description copied from interface: ItemStream
      Open the stream for the provided ExecutionContext.
      Parameters:
      executionContext - current step's ExecutionContext. Will be the executionContext from the last run of the step on a restart.
      See Also:
    • close

      public void close()
      Description copied from interface: ItemStream
      If any resources are needed for the stream to operate they need to be destroyed here. Once this method has been called all other methods (except open) may throw an exception.