Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
MapReduce >> mail # user >> ClassCastException


Copy link to this message
-
Re: ClassCastException
http://www.ibm.com/developerworks/xml/library/x-stax2.html

On Thu, Oct 7, 2010 at 2:54 PM, Johannes.Lichtenberger <
[EMAIL PROTECTED]> wrote:

> On 10/07/2010 05:41 PM, Ted Yu wrote:
> > Since mFormatter.format() returns a String, you don't need to introduce
> > newline.
> > You can call paramOut.writeUTF() to save the String and call
> > paramIn.readUTF() to read it back.
>
> Ok, that's what I did right after replying. My value is a List<XMLEvent>
> or more precisely now it's ListWritable which extends ArrayWritable:
>
>    /** {@link List} of {@link XMLEventWritable}s. */
>    private List<XMLEventWritable> mList;
>
>    /**
>     * Constructor.
>     *
>     * @param paramList
>     *            List of {@link XMLEvent}s.
>     */
>    public ListWritable(final List<XMLEventWritable> paramList) {
>        super(XMLEventWritable.class, paramList.toArray(new
> XMLEventWritable[paramList.size()]));
>        mList = paramList;
>     }
>
>    @Override
>    public void readFields(final DataInput paramIn) throws IOException {
>         readFields(paramIn);
>        mList = Arrays.asList((XMLEventWritable[])get());
>    }
>
> I'm currently writing the XMLEventWritable class, which will be a
> slightly bigger thing (serialization depends on the EventType). I
> haven't coded any serialization/deserialization of Objects before, so
> I've for example something like
>
>    @Override
>    public void write(final DataOutput paramOut) throws IOException {
>         paramOut.write(mEvent.getEventType());
>        paramOut.writeChar(';');
>
>        switch (mEvent.getEventType()) {
>        case XMLStreamConstants.START_DOCUMENT:
>            break;
>        case XMLStreamConstants.START_ELEMENT:
>            try {
>                // Write start tag.
>                final StartElement element = mEvent.asStartElement();
>                final QName name = element.getName();
>                final String prefix = name.getPrefix();
>                if (prefix != null && prefix.length() > 0) {
>                    paramOut.writeUTF(prefix);
>                    paramOut.writeChar(':');
>                }
>                paramOut.writeUTF(name.getLocalPart());
>                ...
>
> I wonder what to write in the read(...) method. I assume I have to read
> in the whole String via paramIn.readUTF() and then parse it and build a
> new XMLEvent. Ah well, I assume no serialization/deserialization class
> of any class which implements XMLEvent
> (
> http://download-llnw.oracle.com/javase/6/docs/api/javax/xml/stream/events/XMLEvent.html
> )
> does exist!?
>
> regards,
> Johannes
>