1

I want to publish a JSON message to a Redis server. This JSON message contains a Base64 encoded audio file and the raw file is around 2.5 MB (which may change further depending on the duration of the audio file). I want to publish this encoded audio file as a JSON message to Redis using an android application. The following is the piece of code I have used:

JSONObject servicedData=receivedJSON.getJSONObject("data");
long dataPublished=jedisConnection.publish(queryNo, servicedData.toString());

I create a JSON object using an android application and extract the data part of it (which contains the encoded audio file) and then publish this to a channel. This code works fine for smaller files but throws an out of memory exception whenever the file size exceeds 2MB. The following is the error log I get:

enter image description here

After doing a lot of research, I figured out that a string uses the device's heap to create the object and I should use a json parser to read the json in chunks but I can't do it as I finally have to publish the entire json as string. Any ideas/help on how I can accomplish this will be really appreciated.

trincot
  • 317,000
  • 35
  • 244
  • 286
BajajG
  • 2,134
  • 2
  • 25
  • 32

0 Answers0