I am using Kafka and following along with this tutorial (https://cwiki.apache.org/confluence/display/KAFKA/Consumer+Group+Example)
After some tweaks, the code compiles and everything runs like it should. my problem is that I am trying to utilize an array of bytes that the Kafka server sends me to do some processing. If I use the default code, everything works fine and the byte array gets converted to a String and displayed on my screen. If I try to read the byte array and assign it to a String so that I can display it to the screen and then parse it nothing happens.
it.next().message() returns a byte array
Default code:
ConsumerIterator<byte[], byte[]> it = m_stream.iterator();
while (it.hasNext())
System.out.println("Thread " + m_threadNumber + ": " + new String(it.next().message()));
My Code that breaks:
ConsumerIterator<byte[], byte[]> it = m_stream.iterator();
String msg= "";
while (it.hasNext())
msg = new String(it.next().message());
System.out.println("Thread " + m_threadNumber + ": " + msg);
Can anybody tell me why I cannot assign the byte array to my String? And of course how to fix my glitch?
I've taken a look at:
Convert byte to string in Java
but none of them seem to apply, they all try to assign the byte array to the String as the String is initialized and I cannot do that here.