String contains a square symbol ???

Discussion in 'Java' started by james.fitzjohn@gmail.com, Jun 27, 2005.

  1. Guest

    Ive sent some data via asocket to another app and when it returns the
    data it contains two [][] squares at the start. how can I get rid of
    these squares i thought they might be \r or \n's but there not
     
    , Jun 27, 2005
    #1
    1. Advertising

  2. wrote:
    > Ive sent some data via asocket to another app and when it returns the
    > data it contains two [][] squares at the start.


    No, it doesn't. The data just contains numbers in the form of bits and
    bytes. It is a matter of interpretation how these numbers are visually
    represented. Most likely you try to print the data as-is, and the
    current font has no glyph for the corresponding codes. In such a case
    Java happens to print squares. But there are no squares in the data - it
    is just that Java decides to represent the particular numbers as squares
    for lack of a better representation.

    > how can I get rid of
    > these squares i thought they might be \r or \n's but there not


    Maybe they are. Get a debugger and look at them. Or use a print
    statement to print out the codes (not the glyphs, but the numbers). Or
    use a network sniffer like ethereal to verify that you indeed have the
    data one the wire which you think you have.

    /Thomas


    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
     
    Thomas Weidenfeller, Jun 27, 2005
    #2
    1. Advertising

  3. Tim Ward Guest

    "Thomas Weidenfeller" <> wrote in message
    news:d9ouct$526$...
    > wrote:
    > > Ive sent some data via asocket to another app and when it returns the
    > > data it contains two [][] squares at the start.

    >
    > No, it doesn't. The data just contains numbers in the form of bits and
    > bytes. It is a matter of interpretation how these numbers are visually
    > represented. Most likely you try to print the data as-is, and the
    > current font has no glyph for the corresponding codes. In such a case
    > Java happens to print squares. But there are no squares in the data - it
    > is just that Java decides to represent the particular numbers as squares
    > for lack of a better representation.


    Could this be a BOM? - I'd have thought, however, that any Jave Unicode
    streaming stuff that he might be using would have known how to deal with
    that.

    --
    Tim Ward
    Brett Ward Limited - www.brettward.co.uk
     
    Tim Ward, Jun 27, 2005
    #3
  4. Guest

    Yes I was sure that they were some sort of undisplayable character such
    as a tab or lf, but how do I get rid off them?


    Im sure the other app isnt sending those characters
     
    , Jun 27, 2005
    #4
  5. Tim Ward Guest

    <> wrote in message
    news:...
    > Yes I was sure that they were some sort of undisplayable character such
    > as a tab or lf, but how do I get rid off them?
    >
    > Im sure the other app isnt sending those characters


    How are you sure? You've sniffed the traffic on the wire?

    --
    Tim Ward
    Brett Ward Limited - www.brettward.co.uk
     
    Tim Ward, Jun 27, 2005
    #5
  6. Tim Ward wrote:
    > Could this be a BOM?


    That's for sure possible, yes, but how could we know? All we know is
    that the OP reads from a socket, but we don't know how it is read. We
    also don't know how the data was written (text or binary) at the other end.

    We both suggested to sniff the traffic, and that is IMHO the most
    sensible way to start.

    > - I'd have thought, however, that any Jave Unicode
    > streaming stuff that he might be using would have known how to deal with
    > that.


    That is definitely not the case. See

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058

    Someone has even copied workaround code from an old discussion in this
    group into the bug report. Still after four years Sun hasn't fixed this.

    /Thomas

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
     
    Thomas Weidenfeller, Jun 27, 2005
    #6
  7. "Tim Ward" <> wrote in message
    news:...
    > "Thomas Weidenfeller" <> wrote in message
    > news:d9ouct$526$...
    >> wrote:
    >> > Ive sent some data via asocket to another app and when it returns the
    >> > data it contains two [][] squares at the start.

    >>
    >> No, it doesn't. The data just contains numbers in the form of bits and
    >> bytes. It is a matter of interpretation how these numbers are visually
    >> represented. Most likely you try to print the data as-is, and the
    >> current font has no glyph for the corresponding codes. In such a case
    >> Java happens to print squares. But there are no squares in the data - it
    >> is just that Java decides to represent the particular numbers as squares
    >> for lack of a better representation.

    >
    > Could this be a BOM? - I'd have thought, however, that any Jave Unicode
    > streaming stuff that he might be using would have known how to deal with
    > that.


    Maybe not. Microsoft sometimes uses a BOM to announce "UTF-8 follows";
    that's non-standard and Java won't interpret it as such. (Though their
    UTF-8 BOM is three bytes.)
     
    Mike Schilling, Jun 28, 2005
    #7
  8. Roedy Green Guest

    On 27 Jun 2005 05:57:31 -0700, wrote or
    quoted :

    >Ive sent some data via asocket to another app and when it returns the
    >data it contains two [][] squares at the start. how can I get rid of
    >these squares i thought they might be \r or \n's but there not


    Most likely those two squares are the unicode byte order marks. You
    simply have to notice them and not try to display them.

    See http://mindprod.com/jgloss/unicode.html for an explanation.

    see also http://mindprod.com/jgloss/encoding.html

    --
    Bush crime family lost/embezzled $3 trillion from Pentagon.
    Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
    http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

    Canadian Mind Products, Roedy Green.
    See http://mindprod.com/iraq.html photos of Bush's war crimes
     
    Roedy Green, Jun 28, 2005
    #8
  9. Mickey Segal Guest

    Mickey Segal, Jun 28, 2005
    #9
  10. Guest

    Thanks for the help guys, the server was sending a \r\n and the java
    string didnt know what to do with it
     
    , Jun 28, 2005
    #10
  11. Mickey Segal Guest

    Mickey Segal, Jun 29, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,238
  2. James Dyer
    Replies:
    5
    Views:
    648
  3. baumann@pan
    Replies:
    1
    Views:
    746
    Richard Bos
    Apr 15, 2005
  4. Song Ma
    Replies:
    2
    Views:
    233
    Charles Oliver Nutter
    Jul 20, 2008
  5. Replies:
    6
    Views:
    1,800
Loading...

Share This Page