background image

Creating a Writer

<< Creating an Event Producer | Creating the Output Factory >>
<< Creating an Event Producer | Creating the Output Factory >>
READNWRITE
S
AMPLE
­ E
VENT
P
RODUCER
C
ONSUMER
.
JAVA
113
else
{
writer.add(event);
}
}
writer.flush();
Creating a Writer
The final step is to create a stream writer in the form of a new
Character
event:
Characters getNewCharactersEvent(Characters event){
if(event.getData().equalsIgnoreCase("Name1")){
return
m_eventFactory.createCharacters(Calendar.getInstance().getTime
().toString());
}
//else return the same event
else return event;
}
Running the Sample
When you run the
EventProducerConsumer
sample, the class is compiled, and
the XML stream is parsed as events and written back to
STDOUT
:
<?xml version="1.0" encoding="UTF-8"?>
<BookCatalogue xmlns="http://www.publishing.org">
<Book>
<Title>Yogasana Vijnana: the Science of Yoga</Title>
<Author>Dhirendra Brahmachari</Author>
<Date>1966</Date>
<ISBN>81-40-34319-4</ISBN>
<Publisher>Dhirendra Yoga Publications</Publisher>
<Cost currency="INR">11.50</Cost>
</Book>
<Book>
<Title>The First and Last Freedom</Title>
<Author>J. Krishnamurti</Author>
<Date>1954</Date>
<ISBN>0-06-064831-7</ISBN>