Andre/Len in case the earlier responses did not answer how to receive a CharSet encoded InputStream to a reader suggest implmenting a Reader which will accomodate charset (such as InputStreamReader) http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStreamReader.html
InputStreamReader public InputStreamReader(InputStream in, Charset cs) Create an InputStreamReader that uses the given charset. Parameters:in - An InputStreamcs - A charsetSince:1.4 BTW: Int to Char conversion String new_string=new java.lang.Integer(int int_input).toString(); BTW: CharToInt conversion int inta=new java.lang.Integer(String str_input).intValue(); HTH Martin ______________________________________________ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. > Date: Thu, 1 Jan 2009 16:23:05 -0500 > From: len.p...@gmail.com > To: users@tomcat.apache.org > Subject: Re: [OT] Basic int/char conversion question > > On Thu, Jan 1, 2009 at 14:39, André Warnier <a...@ice-sa.com> wrote: > > I note with satisfaction that I'm not the only one laboring away on this > > day-after, but you're just all going a bit too fast for me and my growing > > but still limited Java knowledge. > > No hang-over here. :-) > > > In other words, in order to keep my changes and post-festivities headaches > > to a minimum, I would like to keep buf being a StringBuffer. So what I was > > really looking for was the correct alternative to > > buf.append((char) ic); > > which would convert ic from an integer, to the appropriate Unicode > > character, taking into account the "knownEncoding" which I know. > > > > Does that not exist ? > > (I'll leave the InputStreamReader explanation to Chuck.) > > I was guessing that the StringBuffer would soon be converted to a > String (which is the usual case). If not … > > I don't see a simple one-line way to convert one byte to a character > in a given charset. It looks like String and CharsetDecoder are the > classes you're supposed to use. If there's an easy way to convert a > single character, someone please point it out. > > How about this: Read the bytes as bytes, convert them to a String in > the correct charset, and create a StringBuffer from that. Like so: > > String knownEncoding = "ISO-8859-1"; // or "ISO-8859-2" > InputStreamReader fromApp; > fromApp = = new InputStreamReader(socket.getInputStream(), > int ic = 0; > ByteBuffer inbuf = ByteBuffer.allocate(2000); > while((ic = fromApp.read()) != 26 && ic != -1) // hex 1A (SUB) > inbuf.put((char)ic); > byte[] inbytes = new byte[inbuf.limit()]; > inbuf.get(inbytes); > String s = new String(inbytes, knownEncoding); > StringBuffer buf = new StringBuffer(s); > > (I haven't tested this so it might not be correct.) > It's not very efficient but it keeps the changes in one place. > -- > Len _________________________________________________________________ Life on your PC is safer, easier, and more enjoyable with Windows Vista®. http://clk.atdmt.com/MRT/go/127032870/direct/01/