🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #7617

Re: Sockets and BufferedReader (again)

#7617
From: John McGrath TeamB
Date: Thu, 14 Jun 2001 05:44
39 lines
2455 bytes
On 13 Jun 2001 06:02:58 -0700, Bill wrote:

> 
> I've set up a socket connection between a java client
> and non-java server. To read from the socket I use a
> bufferedReader object instantiated from an inputStream
> obtained from the socket.
    :
> It appears that when the incoming bytes in the stream
> have values less than 0x80 or greater than 0xA0, the
> proper value is read. For any value in between the byte
> value is converted to hex 3F.  I suspect it has something
> to do with the filter classes and the definition of the
> unicode but haven't been able to find any specifics. 

Your suspicions are correct.  Somewhere behind your BufferedReader,
you have an InputStreamReader which produces a sequence of Unicode 
characters from a sequence of bytes.  How this is done is controlled
by the encoding of the InputStreamReader.  The default encoding on
your system is probably UTF-8, which uses bytes in that range as 
escapes.

On solution is to change the encoding on the InputStreamReader, which 
is probably what you want to do if the data is indeed characters.  But 
remember that "character" is not the same thing as "byte".  The value 
you will use will depend on the data being sent.  Some values you might 
want to try are "US-ASCII" and "ISO-8859-1".

The other option is to read the bytes from the InputStream directly, 
and interpret them as is appropriate for your program.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <MPG.15921476ee7b56398a29d@forums.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!newsfeed.icl.net!news.algonet.se!algonet!newsfeed1.bredband.com!bredband!uio.no!newsfeed1.uni2.dk!newssuck.uni2.dk!dnews
References: <3b276482$1_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,9d994d5e9f7d3fc3
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-06-13 23:02:17 PST
From: John McGrath  [TeamB] <ng-b@JPMcGrath.net>
Newsgroups: borland.public.jbuilder.java.language
Subject: Re: Sockets and BufferedReader (again)
Date: Thu, 14 Jun 2001 01:44:57 -0400
Message-ID: <MPG.15921476ee7b56398a29d@forums.borland.com>
References: <3b276482$1_1@dnews>
X-Newsreader: MicroPlanet Gravity v2.30
NNTP-Posting-Host: 209.92.40.60
X-Trace: dnews 992497495 209.92.40.60 (13 Jun 2001 22:44:55 -0700)
Lines: 39
X-Authenticated-User: jpmcgrath
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!newsfeed.icl.net!news.algonet.se!algonet!newsfeed1.bredband.com!bredband!uio.no!newsfeed1.uni2.dk!newssuck.uni2.dk!dnews