Search in sources :

Example 36 with BinaryDecoder

use of co.cask.cdap.common.io.BinaryDecoder in project cdap by caskdata.

the class AccessTokenIdentifierCodec method decode.

@Override
public AccessTokenIdentifier decode(byte[] data) throws IOException {
    ByteArrayInputStream bis = new ByteArrayInputStream(data);
    Decoder decoder = new BinaryDecoder(bis);
    DatumReader<AccessTokenIdentifier> reader = readerFactory.create(ACCESS_TOKEN_IDENTIFIER_TYPE, AccessTokenIdentifier.Schemas.getCurrentSchema());
    int readVersion = decoder.readInt();
    Schema readSchema = AccessTokenIdentifier.Schemas.getSchemaVersion(readVersion);
    if (readSchema == null) {
        throw new IOException("Unknown schema version for AccessTokenIdentifier: " + readVersion);
    }
    return reader.read(decoder, readSchema);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Schema(co.cask.cdap.api.data.schema.Schema) IOException(java.io.IOException) BinaryDecoder(co.cask.cdap.common.io.BinaryDecoder) Decoder(co.cask.cdap.common.io.Decoder) BinaryDecoder(co.cask.cdap.common.io.BinaryDecoder)

Aggregations

BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)36 Test (org.junit.Test)23 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)22 PipedInputStream (java.io.PipedInputStream)21 PipedOutputStream (java.io.PipedOutputStream)21 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)19 TypeToken (com.google.common.reflect.TypeToken)17 Schema (co.cask.cdap.api.data.schema.Schema)10 IOException (java.io.IOException)10 Decoder (co.cask.cdap.common.io.Decoder)6 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)6 ByteBufferInputStream (co.cask.common.io.ByteBufferInputStream)6 ImmutableList (com.google.common.collect.ImmutableList)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)5 ByteBuffer (java.nio.ByteBuffer)5 List (java.util.List)5 SchemaHash (co.cask.cdap.api.data.schema.SchemaHash)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3