tags:

views:

41

answers:

3

I'm trying to put together a string that starts with the ascii "Start of Header" character (0x01). I did this on my home computer simple enough with:

String out = "\u0001this";
System.out.println(out);

prints a square to the terminal.. Copy and paste to hex editor and I have my 0x01;

Now at work.. I do the same thing but anything below 0x20 just prints 0x00 to the terminal. As soon as I do "\u0020" I get a space printed to output.. Any idea whats going on.

+3  A: 

Might want to check what file encoding you are using, what charset your JVM runs under by default, etc. Different environments will likely have different settings.

matt b
Default is set to UTF-8.
Josh Long
+1  A: 

This is almost surely a function of your terminal emulator or other program displaying what is written to standard out. This character is by definition non-printable, so what a terminal does to 'display' it likely varies. Some print a box, some a blank, some nothing.

If you are relying on how a non-printable character is printed, which isn't defined, maybe that is the issue? what problem does it cause?

Sean Owen
+1  A: 

Can you write this string directly to a file and open that file in the hex editor? By writing the text to the console and then relying on cut-and-paste to move the bytes to a different application, there are quite a few intermediate steps that could be messing with your data.

I suspect that your code is actually working but you're unintentionally obscuring your own (correct) results.

Tenner
I think I've been chasing rabbits. I printed the string to a file and the hex editor show the correct character. I'm trying to interface with a server application through a socket. I'm receiving messages from the server but it is not responding to my request. I thought it was because the codes weren't being sent correctly but it may be another problem. Thanks!
Josh Long