Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

HashMap Conversion

Thread view: 
andrewzzz - 11 Nov 2006 19:23 GMT
Hi guys,
how do i convert an hash map into a  byte array(being able to restore
this later , without losing data)?
thanks a lot!
bye
Arne Vajhøj - 11 Nov 2006 19:39 GMT
> how do i convert an hash map into a  byte array(being able to restore
> this later , without losing data)?

Serialization !

Arne
andrewzzz - 11 Nov 2006 19:49 GMT
> > how do i convert an hash map into a  byte array(being able to restore
> > this later , without losing data)?Serialization !
>
> Arne

can you send me link where to find out how?
thanks arne!
Arne Vajhøj - 11 Nov 2006 19:53 GMT
>>> how do i convert an hash map into a  byte array(being able to restore
>>> this later , without losing data)?Serialization !
>
> can you send me link where to find out how?

    private static byte[] serialize(Object o) throws IOException {
        ByteArrayOutputStream ba = new ByteArrayOutputStream(1000);
        ObjectOutputStream oba = new ObjectOutputStream(ba);
        oba.writeObject(o);
        return ba.toByteArray();
    }

    private static Object deserialize(byte[] b) throws IOException,
ClassNotFoundException {
        ByteArrayInputStream ba = new ByteArrayInputStream(b);
        ObjectInputStream oba = new ObjectInputStream(ba);
        return oba.readObject();
    }

All objects need to be serializable for this to work though !

Arne
andrewzzz - 11 Nov 2006 20:01 GMT
> >>> how do i convert an hash map into a  byte array(being able to restore
> >>> this later , without losing data)?Serialization !
[quoted text clipped - 16 lines]
>
> Arne

thanks so much! I will try now!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.