Does anyone know why native2ascii generates lower-case hex codes, while Properties.store() produces upper-case hex?
Example:
保存 is encoded as \u4FDD\u5B58 when using Properties.store(), but is encoded as \u4fdd\u5b58 when using native2ascii
Is there any way to control this?
I don’t know why but I do know it doesn’t matter (to Java anyway, it may matter to you a great deal). Unicode escapes are allowed to have upper or lower case hex digits so it really doesn’t matter to Java which one is used (even mixed case is valid).
The reason they’re different is probably something as simple as they were written by two different people.
Is there any way to control it? Not easily from what I can see. It doesn’t appear that
native2asciihas any options to control that output (it allows options to control the JVM but not to that level).Properties.store()uses anOutputStream(andProperties.load()uses anInputStream) which you could probably subclass to filter the Unicode escapes but that seems an awful lot of work for (what looks like) dubious benefit.Perhaps if you could tell us why you need this, there may be another way.
Update 1:
One thing that you could do is to pass the
native2asciioutput through a filter which turns the Unicode escape sequeces into uppercase. The following codeucunicode.cshould be able to do this although I’ve only given it cursory testing. Simply execute:and you should see the likes of
\u00EF\u00BB\u00BFinstead of\u00ef\u00bb\u00bf.}
There may be edge cases that this doesn’t handle well. I’m pretty certain it will handle all valid input but may break on invalid input like
\u1\\u0000but, since that means yournative2asciiis broken, you’ll need to debug them yourself. This is a good start however.Update 2:
Or, as a last-ditch solution, the OpenJDK project has the actual source files for
native2asciiinjdk\src\share\classes\sun\tools\native2ascii\(and just about everything else that’s not encumbered by copyright) which you could bring down and compile yourself (GPL2 applies). The files areMain.java,A2NFilter.javaandN2AFilter.java(and a couple of resource files). You’d simply have to changeN2AFilter.javato call:instead of just:
In fact, by examining that source code, you can see that
Properties.store()(injdk/src/share/classes/java/util/Properties.java) uses the following functions to create it’s Unicode escapes:This explains why it generates upper case while
native2asciiproduces lower case.