1

So I'm trying to understand how a special character normally seen as '<' could be converted to '+ADw-' in UTF-7.

Is there an online tool or a built in library in JavaScript or Java that can do this?

What is the math behind this? I know that UTF-7 uses 7bits to store the character, so I am guessing that the '+ADw-' is just the numerical representation of '<' in ASCII? Meaning, if you converted to '<' to a number, that would be equal to '+ADw-' as a number?

Thanks!

1
  • No, UTF-7 uses one byte to store a 7-bit value, which is either the entire codepoint or some of its 21 bits, depending on the codepoint being encoded. Commented Sep 8, 2015 at 22:42

1 Answer 1

2

Java itself does not have UTF-7 support.

But that library provides a UTF-7 charset implementation and when you add its jar to your Java application you can simply write:

OutputStreamWriter out = new OutputStreamWriter(System.out, "UTF-7");
out.write("<");

to see how a string is translated into UTF-7.

Sign up to request clarification or add additional context in comments.

6 Comments

Hey I tried using that but when I looked in the source of the jutf7 library it doesn't have a OutputStreamWriter, it uses java.io.OutputStreamWriter: Using this code I get no result, but I didnt just include the jar though, I copied all the src into my Test project in eclipse:
import java.io.IOException; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; public class Test { public static void main(String[] args) { OutputStreamWriter out; try { out = new OutputStreamWriter(System.out, "UTF-7"); out.write("<"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Yes the OutputStreamWriter in my example is java.io.OutputStreamWriter. Copying the sources to your project might not be enough. If you look into the jutf7-1.0.0.jar there is also a file META-INF/services/java.nio.charset.spi.CharsetProvider which is needed to register the UTF-7 charset. Therefore include this file as resource to your project or simply use the jar.
Following the usage info in the src, I get bad results too: java -jar jutf7-1.0.0.jar encode < The syntax of the command is incorrect. java -jar jutf7-1.0.0.jar encode a a C:\Downloads\jutf7-1.0.0\jutf7-1.0.0>java -jar jutf7-1.0.0.jar enc de b b C:\Downloads\jutf7-1.0.0\jutf7-1.0.0>java -jar jutf7-1.0.0.jar enc de ss ss C:\Downloads\jutf7-1.0.0\jutf7-1.0.0>java -jar jutf7-1.0.0.jar enc de 1 1 C:\Downloads\jutf7-1.0.0\jutf7-1.0.0>java -jar jutf7-1.0.0.jar enc de < The syntax of the command is incorrect.
wero, thank you so much for your guidance. I added the jar AND the src to the build path of the sample project in eclipse but its still not displaying anything. I will continue to tinker around with this and keep you posted.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.