Author Topic: [GENERAL/JAVA] I'm getting boxes! :(  (Read 3657 times)

0 Members and 1 Guest are viewing this topic.

Offline dynobird

  • Newbie
  • *
  • Posts: 26
  • I'm new here!
    • View Profile
[GENERAL/JAVA] I'm getting boxes! :(
« on: August 28, 2005, 12:08:56 pm »
NOTE: This is for CHAT protocol.

I just learned that the boxes I'm getting (which look like the outline of a square not filled in) represents a symbol that my computer can't interpret. What I don't understand is...

Why this doesn't show the boxes...
Code: [Select]
while(true) {
    newWindow.addText((char)in.read()); //which reads one char at a time and, one at a time, adds it to my display text
}

Yet this does...
Code: [Select]
/* run method in receive thread
 * reads a byte at a time, if byte isn't null adds to byte array,
 * then make string out of that byte array once it gets the values 13 and 10 (chars \r \n)
 */
public void run() {
        byte[] bytesIn;
        byte newByte;
        int i;
        while (true) {
            bytesIn = new byte[1000];
            i = 0;
            try {
                do {
                    for(int j = 0; j < 2; j++) {            // I'll be checking two bytes, 13 and 10
                        newByte = (byte)in.read();          // so i have to read two at a time
                        if (newByte != 0x00) {                      // my attempt at fixing the box problem, does it with and without this piece though...
                            bytesIn[i] = newByte;                         
                            i++;
                        }
                    }
                }
                while(bytesIn[i-2] != 0x0d && bytesIn[i-1] != 0x0a); //checking for \r and \n, if it gets them it includes them then stops
               
                String message = new String(bytesIn);
                newWindow.addText(message);
            }
            catch (IOException e) {
                newWindow.addText(e.toString());
            }
        }
}

Is there a better way to do this? Newby made a good suggestion on the newline character thread,
to do the equivalent of this c++ piece in java:
Code: [Select]
string[] IncomingData = IncomingInfo.Split("\r\n".ToCharArray());I know it shouldn't be hard to convert c++ to java lol cause they are both OOP but the problem is
that IO in java is kinda a bitch...
It seems that IncomingInfo is a character reader that reads characters, remembers them, and once it comes to \r\n it turns the characters into a character array and then he makes that into a string. But, what should I use in Java for a character reader that *remembers the characters* so it can turn them into a character array later when I want it to...

EDIT: Oh, I guess IncomingInfo is a String that you keep adding a char array to and then refresh the char array... I tried that in Java but it still gave me boxes !! :( What's up with all these damn boxes?!
« Last Edit: August 28, 2005, 07:44:51 pm by dynobird »