Article View: borland.public.jbuilder.java.api
Article #2894Problems with serialization (newbie)
From: J�rn Horvik
Date: Fri, 08 Oct 1999 00:00
Date: Fri, 08 Oct 1999 00:00
59 lines
2023 bytes
2023 bytes
Hi All,
I am quite new to java, so please bear with me.
I try to convert a byte array to an objcet using serialization, but I get an
exception when I execute the following code:
byte[] buf = new byte[17];
// Populate the array
...
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
ObjectInputStream is = new ObjectInputStream(bais); // Fails
..
What am I doing wrong?
Eventually I'll need to read a UDP datagram and store it in an object this
code is just a test to see how I can convert a byte array to an object.
Any hints will be greatly appreciated.
TIA
Code:
public class NetComm implements Serializable
{
....
public void testconv()
{
byte[] buf = new byte[17];
byte i;
for (i = 0; i < 17; i++)
{
buf[i] = i;
}
EmXBroadcast putgm = new EmXBroadcast();
try {
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
ObjectInputStream is = new ObjectInputStream(bais);
putgm = (EmXBroadcast) is.readObject();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e1)
{
e1.printStackTrace();
}
}
....
}
--
J�rn Horvik
SW Engineer - Kongsberg Simrad AS
http://www.kongsberg-simrad.com
Technical Details
Message-ID:
<7tkcfq$fko$1@oslo-nntp.eunet.no>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 1089d0,cfe201878e236695,start X-Google-Attributes: gid1089d0,public X-Google-Thread: fecd1,cfe201878e236695,start X-Google-Attributes: gidfecd1,public From: "J�rn Horvik" <jorn.horvik@kongsberg.simrad.nospam> Subject: Problems with serialization (newbie) Date: 1999/10/08 Message-ID: <7tkcfq$fko$1@oslo-nntp.eunet.no> X-Deja-AN: 534250786 X-Trace: oslo-nntp.eunet.no 939373882 16024 193.69.73.6 (8 Oct 1999 09:11:22 GMT) X-MSMail-Priority: Normal X-Priority: 3 NNTP-Posting-Date: 8 Oct 1999 09:11:22 GMT Newsgroups: borland.public.jbuilder.java.api,comp.lang.java.api X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 X-Complaints-To: newsmaster@eunet.no