sknop commented on a change in pull request #9950:
URL: https://github.com/apache/kafka/pull/9950#discussion_r580884849



##########
File path: 
connect/transforms/src/main/java/org/apache/kafka/connect/transforms/Cast.java
##########
@@ -364,11 +365,24 @@ private static String castToString(Object value) {
         if (value instanceof java.util.Date) {
             java.util.Date dateValue = (java.util.Date) value;
             return Values.dateFormatFor(dateValue).format(dateValue);
+        } else if (value instanceof ByteBuffer) {
+            ByteBuffer byteBuffer = (ByteBuffer) value;
+            return castByteArrayToString(byteBuffer.array());
+        } else if (value instanceof byte[]) {
+            return castByteArrayToString((byte[]) value);
         } else {
             return value.toString();
         }
     }
 
+    private static String castByteArrayToString(byte[] array) {
+        StringBuilder sbuf = new StringBuilder();
+        for (byte b : array) {
+            sbuf.append(String.format("%02X", b));

Review comment:
       If base64 is the better choice we shall go with that. Would we need to 
adjust the JIRA ticket to reflect this?
   
   I just ran a little test in the JShell:
   
   jshell> byte[] byteArray = new byte[] {(byte) 0xFE, (byte) 0xDC, (byte) 
0xBA, (byte) 0x98, 0x76, 0x54, 0x32, 0x10};
   byteArray ==> byte[8] { -2, -36, -70, -104, 118, 84, 50, 16 }
   
   jshell> Base64.getEncoder().encode(byteArray)
   $2 ==> byte[12] { 47, 116, 121, 54, 109, 72, 90, 85, 77, 104, 65, 61 }
   
   jshell> Base64.getEncoder().encodeToString(byteArray)
   $3 ==> "/ty6mHZUMhA="
   
   jshell> Base64.getEncoder().withoutPadding().encodeToString(byteArray)
   $4 ==> "/ty6mHZUMhA"
   
   Would you suggest using padding or not?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to