Search in sources :

Example 1 with FormatStreamEventDecoder

use of co.cask.cdap.data.stream.decoder.FormatStreamEventDecoder in project cdap by caskdata.

the class AbstractStreamInputFormat method createStreamEventDecoder.

@SuppressWarnings("unchecked")
protected StreamEventDecoder<K, V> createStreamEventDecoder(Configuration conf) {
    Class<? extends StreamEventDecoder> decoderClass = getDecoderClass(conf);
    Preconditions.checkNotNull(decoderClass, "Failed to load stream event decoder %s", conf.get(DECODER_TYPE));
    try {
        // to format the stream body.
        if (decoderClass.isAssignableFrom(FormatStreamEventDecoder.class)) {
            try {
                RecordFormat<StreamEvent, V> bodyFormat = getInitializedFormat(conf);
                return (StreamEventDecoder<K, V>) new FormatStreamEventDecoder(bodyFormat);
            } catch (Exception e) {
                throw new IllegalArgumentException("Unable to get the stream body format.");
            }
        } else {
            return (StreamEventDecoder<K, V>) decoderClass.newInstance();
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : IdentityStreamEventDecoder(co.cask.cdap.data.stream.decoder.IdentityStreamEventDecoder) StringStreamEventDecoder(co.cask.cdap.data.stream.decoder.StringStreamEventDecoder) StreamEventDecoder(co.cask.cdap.api.stream.StreamEventDecoder) BytesStreamEventDecoder(co.cask.cdap.data.stream.decoder.BytesStreamEventDecoder) TextStreamEventDecoder(co.cask.cdap.data.stream.decoder.TextStreamEventDecoder) FormatStreamEventDecoder(co.cask.cdap.data.stream.decoder.FormatStreamEventDecoder) StreamEvent(co.cask.cdap.api.flow.flowlet.StreamEvent) UnsupportedTypeException(co.cask.cdap.api.data.schema.UnsupportedTypeException) IOException(java.io.IOException) FormatStreamEventDecoder(co.cask.cdap.data.stream.decoder.FormatStreamEventDecoder)

Aggregations

UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)1 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)1 StreamEventDecoder (co.cask.cdap.api.stream.StreamEventDecoder)1 BytesStreamEventDecoder (co.cask.cdap.data.stream.decoder.BytesStreamEventDecoder)1 FormatStreamEventDecoder (co.cask.cdap.data.stream.decoder.FormatStreamEventDecoder)1 IdentityStreamEventDecoder (co.cask.cdap.data.stream.decoder.IdentityStreamEventDecoder)1 StringStreamEventDecoder (co.cask.cdap.data.stream.decoder.StringStreamEventDecoder)1 TextStreamEventDecoder (co.cask.cdap.data.stream.decoder.TextStreamEventDecoder)1 IOException (java.io.IOException)1