protected byte [ ] getFieldAsBytes ( GenericRecord record , String fieldLocation ) throws Exception { Optional < Object > bytesValue = AvroUtils . getFieldValue ( record , fieldLocation ) ; if ( ! bytesValue . isPresent ( ) ) { throw new Exception ( "Bytes value with key " + fieldLocation + " not found in the record" ) ; } ByteBuffer bb = ( ByteBuffer ) bytesValue . get ( ) ; if ( bb . hasArray ( ) ) { return bb . array ( ) ; } else { byte [ ] payloadBytes = new byte [ bb . remaining ( ) ] ; bb . get ( payloadBytes ) ; return payloadBytes ; } }
Get field value byte array