override the Serializable method

How do i override the readObject for my message class that i recieve from the network using a datagram socket ?
Do you have an example .
sectorAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
heyhey_Connect With a Mentor Commented:
time for Answer.
0
 
heyhey_Commented:
do tou need something like this ?
(btw. take a look at "Java Tutorial" - online tutorial at www.javasoft.com)


long l;

private void writeObject(ObjectOutputStream s)
  throws IOException
{
  s.defaultWriteObject();
  s.writeLong(l);
}


private void readObject(ObjectInputStream s)
  throws ClassNotFoundException, IOException
{
   s.defaultReadObject();
   l = s.readLong();
}

0
 
sectorAuthor Commented:
Can you tell me how do i parse from an byte[] to int ?
0
 
heyhey_Commented:
the easiest solution is
byte[] buf;
int i = buf[pos] << 24 | buf[pos+1] << 16 | buf[pos+2] < 8 | buf[pos]


'- Class java.io.DataInputStream -
 public final int readInt() throws IOException
Reads a signed 32-bit integer from this data input stream. This method reads four bytes from the underlying input stream. If the bytes read, in order, are b1, b2, b3, and b4, where 0 <= b1, b2, b3, b4 <= 255, then the result is equal to:

(b1 << 24) | (b2 << 16) + (b3 << 8) +b4'
0
 
MoondancerCommented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  Or if you are an EE Pro user, click the link below to select open items for your Member ID using Power Search:
http://www.experts-exchange.com/jsp/qPowerSearch.jsp.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0
All Courses

From novice to tech pro — start learning today.