java.netunicodeutf-8ucs2

trying to figure out what kind of unicode should i have


I'm working on spring boot on a project that fetch the data from the database then use post method to send them through HTTP post request, everything is okay but with Latina, the data i have in database encoded with: ISO 8859-6 i have encoded it to UTF-8 and UTF-16 but still it returns unreadable text question marks and special characters

test example in Arabic :

مرحبا

should be like this to be valid and reliable after post method :

06450631062d06280627

i can't figure out what kind of encoding happend here, now im doing integration from .NET to java:

this what they used in .NET :

public static String UnicodeStr2HexStr(String strMessage)
        {
            byte[] ba = Encoding.BigEndianUnicode.GetBytes(strMessage);
            String strHex = BitConverter.ToString(ba);
            strHex = strHex.Replace("-", "");
            return strHex;
        }

i just need to know what kind of encoding happend here to apply in java, and it would helpfull if someone provide me with way:

i have tried this but it return different value:

String encodedWithISO88591 = "مرحبا;
String decodedToUTF8 = new String(encodedWithISO88591.getBytes("ISO-8859-1"), "UTF-8");

Solution

  • What you're looking to get is the hex representation of the Arabic String in UTF-16BE

    String yourVal = "مرحبا";
    System.out.println(DatatypeConverter.printHexBinary(yourVal.getBytes(StandardCharsets.UTF_16BE)));
    

    output will be :

    06450631062D06280627