How to convert zipped binary data to String format?
Here Source is kafka consumer component. It contains all the zipped binary data.
So output type is byte[] format. Now we can consume all the data from mentioned kafka topic.
After kafka component we need to place tJavaRow to write the code to convert the zipped binary data string format.
Below mentioned details are decency that we need to import for the java code
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.zip.GZIPInputStream;
byte[] inputData = input_row.payload;
try {
//calculate starting time
log.info("UncompressMessage Activity START");
long startTime = System.currentTimeMillis();
// Create a GZIPInputStream to decompress the data
ByteArrayInputStream byteStream = new ByteArrayInputStream(inputData);
GZIPInputStream gzipStream = new GZIPInputStream(byteStream);
// Read the decompressed data into a byte array
ByteArrayOutputStream outputByteStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = gzipStream.read(buffer)) > 0) {
outputByteStream.write(buffer, 0, len);
}
// Convert the decompressed data to a string
String outputData = outputByteStream.toString("UTF-8");
// Set the output string data
output_row.payload = outputData;
} catch (Exception e) {
e.printStackTrace();
}
And above code will help to convert zipped binary data to string format. now we can use tLog component to print the data.