Java: UTF-8 encoding length limit between local application and Google App Engine

I am trying to get a Google App Engine web application to send UTF-8 encoded text to a browser. I do this by writing this:

byte[] utf8Bytes = "æøΓ₯".getBytes("UTF-8"); 

When I do this locally, I get an array of bytes with 6 bytes. When I do this in the Google App Engine, I get an array with 12 bytes. Strange, huh ??

Does anyone know why?

I managed to write UTF-8 encoded text from GAE, by encoding the bytes themselves, and write the raw bytes. Like this:

 output.write(new byte[]{(byte)0xc3, (byte)0xa5, (byte) 0xc3, (byte)0xa6, (byte)0xc3, (byte)0xb8 }); 

And it really works. But does anyone have an answer to the question why String are encoded differently in GAE than they are locally?

Note. Character encoding using unicode processing like this:

 byte[] utf8Bytes = "\u00E5\u00F8\u00E6".getBytes("UTF-8"); 
+4
source share
2 answers

The bytes you get from GAE make me assume that the source file with the letter "ΓΈΓ₯ is saved as UTF-8, but compiled with a compiler that expects the source files to be encoded as ISO-8859-1, ISO-8859 -15 or CP1252.

If you are creating source code using Ant or Maven, you need to specify the encoding of the source file in the build.xml or pom.xml file.

+5
source

Are you sure that you set the content encoding to your HttpServletResponse before you get Writer?

+1
source

All Articles