Search in sources :

Example 1 with ChainedDecoder

use of org.grails.encoder.ChainedDecoder in project grails-core by grails.

the class BasicCodecLookup method createChainedCodecInstance.

protected <T extends CodecIdentifierProvider> T createChainedCodecInstance(String codecName, ConcurrentMap<String, T> map, Class<T> returnType) {
    String[] codecs = codecName.split(",");
    List<T> codecInstances = new ArrayList<T>(codecs.length);
    for (int i = 0; i < codecs.length; i++) {
        T codecInstance = map.get(codecs[i]);
        if (codecInstance != null) {
            codecInstances.add(codecInstance);
        }
    }
    if (returnType == Encoder.class) {
        List<StreamingEncoder> streamingEncoders = ChainedEncoders.toStreamingEncoders((List<Encoder>) codecInstances);
        if (streamingEncoders == null) {
            throw new RuntimeException("ChainedEncoder only supports StreamingEncoder instances. Couldn't build chained encoder for '" + codecName + "'");
        } else {
            return (T) ChainedEncoder.createFor(streamingEncoders);
        }
    } else {
        Collections.reverse(codecInstances);
        return (T) new ChainedDecoder(codecInstances.toArray(new Decoder[codecInstances.size()]));
    }
}
Also used : StreamingEncoder(org.grails.encoder.StreamingEncoder) Encoder(org.grails.encoder.Encoder) ChainedEncoder(org.grails.encoder.ChainedEncoder) ArrayList(java.util.ArrayList) ChainedDecoder(org.grails.encoder.ChainedDecoder) StreamingEncoder(org.grails.encoder.StreamingEncoder)

Aggregations

ArrayList (java.util.ArrayList)1 ChainedDecoder (org.grails.encoder.ChainedDecoder)1 ChainedEncoder (org.grails.encoder.ChainedEncoder)1 Encoder (org.grails.encoder.Encoder)1 StreamingEncoder (org.grails.encoder.StreamingEncoder)1