case STRING:
// TODO: could be null
try {
return URLEncoder.encode(value.toString(), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new DatasetIOException("Failed to encode value: " + value, e);
}
default:
// otherwise, encode as Avro binary and then base64
DatumWriter writer = ReflectData.get().createDatumWriter(schema);
ByteArrayOutputStream out = new ByteArrayOutputStream();
BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out, null);
try {
writer.write(value, encoder);
encoder.flush();
} catch (IOException e) {
throw new DatasetIOException("Cannot encode Avro value", e);
}
return Base64.encodeBase64URLSafeString(out.toByteArray());
}
}