Search in sources :

Example 6 with Decoder

use of co.cask.cdap.common.io.Decoder 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)6 Decoder (co.cask.cdap.common.io.Decoder)6 IOException (java.io.IOException)4 Schema (co.cask.cdap.api.data.schema.Schema)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteBuffer (java.nio.ByteBuffer)3 SchemaHash (co.cask.cdap.api.data.schema.SchemaHash)2 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)2 ByteBufferInputStream (co.cask.common.io.ByteBufferInputStream)2 StreamEventData (co.cask.cdap.api.stream.StreamEventData)1 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)1 Encoder (co.cask.cdap.common.io.Encoder)1 DequeueResult (co.cask.cdap.data2.queue.DequeueResult)1 ImmutableList (com.google.common.collect.ImmutableList)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 IntBuffer (java.nio.IntBuffer)1 Test (org.junit.Test)1