?
Solved

how to convert an object to into a byte

Posted on 2003-03-05
13
Medium Priority
?
222 Views
Last Modified: 2010-03-31
well, I've an object of type MyClass. what I want to do is to convert such object in byte or byte[] so that I can send it through a stream.

Any suggests??
0
Comment
Question by:Solarin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +4
13 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 8071152
use ObjectOutputStream.writeObject()
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8071156
This should tell you all you need to know:
http://java.sun.com/docs/books/tutorial/essential/io/serializing.html 
 
0
 

Author Comment

by:Solarin
ID: 8071221
ok, the problem is quite different.

i've a DatagramPacket(byte[]...); and i've to put the byte value of the object in that field. it's nothing to do with streams.. :(
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 8071253
In that case, chain the ObjectOutputStream above a ByteArrayOutputStream and use the latter's toBytesArray to get the array of bytes
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8071257
>>toBytesArray

should have been

>>toByteArray
0
 
LVL 1

Expert Comment

by:umangjoshi
ID: 8071411
implements java.io.Serializable in MyClass
and user ObjectOutputStream to send it
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8071695
> implements java.io.Serializable in MyClass
> and user ObjectOutputStream to send it

Please don't repeat things that have already been said...
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8125664
Try:

byte arr[] = MyClassObject.toString ().getBytes () ;

Then make a DatagramPacket with this byte array.

Mayank.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8544908
How about rating it now?
0
 

Expert Comment

by:CleanupPing
ID: 9058907
Solarin:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9762237
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept CEHJ's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TimYates
EE Cleanup Volunteer
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9813884
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 1 hour left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question