This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm trying to take an encryption function from a Powerbuilder app to Java. I can't use the Security classes because it complicates things for other apps still in PB. I also don't have time to figure it out as I'm a bit new to Java, though not to programming.
So, is there a way I can get an ascii value of a char? I know Java likes unicode. Maybe I could first get the unicode value and then get the ascii value for that?
All ASCII char values are identical to the corresponding Unicode values, for 0-127. So there's really no conversion to do - other than maybe cast to byte:
If you encounter characters in the range 128-255, those aren't really ASCII - but they can be represented in several other ASCII-based encodings, like ISO-8859-1 or Cp-1052 (Windows extended ASCII). However you won't be able to do this correctly unless you determine exactly which encoding is really being used.
Note also that the NIO Charset class is not really necessary; you can also perform conversion with classes like InputStreamReader and OutputStreamWriter. And the String class has useful methods, like new String(byte, String) and getBytes(String). The NIO classes give you greater control over how the conversion takes place (e.g. what do do if there's an error) and it can be more efficient (especially if you're using NIO classes for other parts of your program). But if you're using an older JDK (before 1.4) or if you're new to NIO, the other classes I mentioned should work fine. [ May 19, 2004: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
Joined: Jan 22, 2004
True, the NIO package is not necessary, but I thought the tutorial would be useful because it talks specifically about porting legacy code into Java.