Pregunta

So, an Android String is internally stored as UTF-16. What I do not know is if it is Big Endian or Little Endian that is used internally.

If I call getBytes("UTF"), I get back a BE byte array with a BOM. Does this mean that this is the way the strings are stored internally as well?

I have a C API that I need to call with a byte buffer of UTF-16 characters. I can adapt the C API to manage endianess if needed.

What I want to avoid is to do array copying in the Java level if not needed just to manage endianess. For that to work I need to know if the String internally is stored in Big or Little endian. If the String internally is stored in Little Endian, I prefer just to call getBytes("UTF16-LE") and pass it straight away as Little Endian to the native code.

So anyone know what Android uses under the hood and what call to getBytes(...) that is the most efficient?

¿Fue útil?

Solución

You can check the value returned by ByteOrder.nativeOrder(). The jdk javadoc hints that using the native endianness can improve performance. But you should probably check the impact on android before rushing to conclusions.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top