class KijiCellRewriter extends KijiPivoter {

  public static <T, U> DecodedCell<T> convertAvro(
      DecodedCell<U> original,
      Schema schema
  ) throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();

    // Encode original datum to bytes:
    final Encoder encoder = EncoderFactory.get().directBinaryEncoder(baos, null);
    final DatumWriter<U> writer = new GenericDatumWriter<U>(original.getWriterSchema());
    writer.write(original.getData(), encoder);
    encoder.flush();

    // Decode bytes according to the new schema:
    final Decoder decoder = DecoderFactory.get().binaryDecoder(baos.toByteArray(), null);
    final DatumReader<T> reader =
        new GenericDatumReader<T>(original.getWriterSchema(), schema);
    final T data = reader.read(null, decoder);

    return new DecodedCell<T>(schema, data);
  }

}