M
My Name
I am new to Java coming from Win32 C/CPP. After a lot of searching, I have
yet
to find an example explaining the best solution for reading and writing a
binary
message from a socket. All the devices I work with write raw memory
structures to the stream. They are usually proceeded with integer byte
lengths
to help determine message boundaries. In some cases, the message is
variable length with structures inside of structure etc.
1) I have never seen the output for a serialized object in Java.
If I was working with a fixed message length could I try to load
an object by creating a serializable one and loading into it from the stream
?
Or does serialized objects include overhead bytes/data preventing this ?
2) The only solution I came up with is to use class ObjectInputStream
and use the methods to extract each field type one after another and
save values into a respective object / storage.
This seems like a lot method calls() especially when lots of fields
aren't always needed.!
Should I use the buffered stream class in this scenario ?
3) Finally, it seems like I could read the entire message into a java Byte
array BUT
is there any way to convert parts of byte array into long, short,
floats, strings etc ?
This would be my first choice.
Thanks all,
yet
to find an example explaining the best solution for reading and writing a
binary
message from a socket. All the devices I work with write raw memory
structures to the stream. They are usually proceeded with integer byte
lengths
to help determine message boundaries. In some cases, the message is
variable length with structures inside of structure etc.
1) I have never seen the output for a serialized object in Java.
If I was working with a fixed message length could I try to load
an object by creating a serializable one and loading into it from the stream
?
Or does serialized objects include overhead bytes/data preventing this ?
2) The only solution I came up with is to use class ObjectInputStream
and use the methods to extract each field type one after another and
save values into a respective object / storage.
This seems like a lot method calls() especially when lots of fields
aren't always needed.!
Should I use the buffered stream class in this scenario ?
3) Finally, it seems like I could read the entire message into a java Byte
array BUT
is there any way to convert parts of byte array into long, short,
floats, strings etc ?
This would be my first choice.
Thanks all,