Alex Blewitt
Posts: 44
Nickname: alblue
Registered: Apr, 2003
|
|
Re: Help with toHexString
|
Posted: Apr 6, 2004 3:12 PM
|
|
You could also use a DataInputStream, which allows the construction/deconstruction of such data on the fly (and it uses Network Byte Order too).
DataInputStream dis = new DataInputStream(in); length = dis.readInt(); // length of data; int=32bits=4bytes byte[] buffer = new byte[length]; dis.readFully(buffer); // contents of data
Then do whatever you want with the buffer. Of course, if you want to stream it in, you can always read into a partial array.
If the data is always ASCII, then you can use
dis.readUTF()
which will read in the data as a string; though I don't know what terminator it will use. I think it will default to UTF-8 (of which ASCII is a subset), but it might use UTF-16, which won't work.
Lastly, if you know it's always going to be text, you could read it into a byte buffer first, then copy each letter across into a char array instead, and then use something like the new String(chararray) constructor.
|
|