Package org.springframework.batch.item.avro

# Class AvroItemReader<T>

java.lang.Object
org.springframework.batch.item.ItemStreamSupport
org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
org.springframework.batch.item.avro.AvroItemReader<T>

All Implemented Interfaces:
  `ItemReader<T>`, `ItemStream`, `ItemStreamReader<T>`

public class AvroItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
An `ItemReader` that deserializes data from a `Resource` containing serialized Avro objects.

Since:
  4.2
Author:
  David Turanski, Mahmoud Ben Hassine

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AvroItemReader(org.springframework.core.io.Resource resource, Class<T> clazz)`
  `AvroItemReader(org.springframework.core.io.Resource data, org.springframework.core.io.Resource schema)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `doClose()`
  Close the resources opened in `AbstractItemCountingItemStreamItemReader.doOpen()`.
  `protected void`
  `doOpen()`
  Open resources necessary to start reading input.
  `protected T`
  `doRead()`
  Read next item from input.
  `void`
  `setEmbeddedSchema(boolean embeddedSchema)`
  Disable or enable reading an embedded Avro schema.

  ### Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader

  `close, getCurrentItemCount, isSaveState, jumpToItem, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update`

  ### Methods inherited from class org.springframework.batch.item.ItemStreamSupport

  `getExecutionContextKey, setExecutionContextName, setName`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AvroItemReader

    public AvroItemReader(org.springframework.core.io.Resource resource, Class<T> clazz)
    Parameters:
      `resource` - the `Resource` containing objects serialized with Avro.
      `clazz` - the data type to be deserialized.

  - ### AvroItemReader

    public AvroItemReader(org.springframework.core.io.Resource data, org.springframework.core.io.Resource schema)
    Parameters:
      `data` - the `Resource` containing the data to be read.
      `schema` - the `Resource` containing the Avro schema.

- ## Method Details

  - ### setEmbeddedSchema

    public void setEmbeddedSchema(boolean embeddedSchema)
    Disable or enable reading an embedded Avro schema. True by default.
    Parameters:
      `embeddedSchema` - set to false to if the input does not embed an Avro schema.

  - ### doRead

    @Nullable protected T doRead() throws Exception
    Description copied from class: `AbstractItemCountingItemStreamItemReader`
    Read next item from input.
    Specified by:
      `doRead` in class `AbstractItemCountingItemStreamItemReader<T>`
    Returns:
      an item or `null` if the data source is exhausted
    Throws:
      `Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework

  - ### doOpen

    protected void doOpen() throws Exception
    Description copied from class: `AbstractItemCountingItemStreamItemReader`
    Open resources necessary to start reading input.
    Specified by:
      `doOpen` in class `AbstractItemCountingItemStreamItemReader<T>`
    Throws:
      `Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework

  - ### doClose

    protected void doClose() throws Exception
    Description copied from class: `AbstractItemCountingItemStreamItemReader`
    Close the resources opened in `AbstractItemCountingItemStreamItemReader.doOpen()`.
    Specified by:
      `doClose` in class `AbstractItemCountingItemStreamItemReader<T>`
    Throws:
      `Exception` - Allows subclasses to throw checked exceptions for interpretation by the framework