Saturday, August 20, 2016

Converting byte array to string without loosing data

Recently I had to deal with poor Redis interface, that didn't allowed to store bytes and it was not possible to update it or change. Redis handles bytes perfectly for keys and data, but there was no way to pass it. Standard solution for this task is to use Base64, but for my case overhead was too big as I had to store hundreds of millions of records. UTF is not good too, as it is ruining data. Finally, I found that right encoding for this task is to use ISO-8859-1 encoding and it works just fine.

new String([10,20,-30,126] as byte[], "ISO-8859-1").getBytes("ISO-8859-1");

1 comment:

  1. It's important to note that while this approach may work for your specific situation, it's always good to carefully consider the limitations and requirements of your system. Depending on the use case, other encoding methods such as Base64 or UTF-8 may be more suitable.

    Regarding your suggestion to use FMwhatsapp in our daily lives, it is safe for us. FM whatsapp offer additional features compared to the official WhatsApp application, and provide high security for which no one can access our account easily.