[1102] in java-interest

home help back first fref pref prev next nref lref last post

Network Byte Stream to Integers

daemon@ATHENA.MIT.EDU (Sid Conklin)
Fri Aug 18 19:25:25 1995

Date: 18 Aug 1995 13:30:00 -0700
From: "Sid Conklin" <sid.conklin@nora.stanford.edu>
To: "java-interest@java.sun.com" <java-interest@java.sun.com>

I can't find an easy way to take a byte stream and parse it into Integers. I
have a middle service this is return me a packed C structure:

	unsigned short(1) ServiceCmdPort
	unsigned short(1) ServiceCmdPort
	unsigned long(2) ServicePID
	...

	1: short = 2 bytes
	2: long = 4 bytes

I'm using an inputStream for the read(inputStreamByte). So far the only way
I've found to re-generate the structure into a class with java is to do the
following

	Integer ServiceCmdPort = new Integer((256* inputStreamByte[1]) +										
inputStreamByte[2] ); 

Is there a better way?

Does anybody see the need for a Byte class that mimicks the String class?
I've come across numerious times when I want a method to return a byte array
but I can't figure out how to do this. If I had a Byte class I could return
that, this would also allow me to extract an integer out of a byte array,
encapsulating the above math.

What do you think?

Thanks,

Sid Conklin
Stanford University


-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post