Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > HashMap Conversion

Reply
Thread Tools

HashMap Conversion

 
 
andrewzzz
Guest
Posts: n/a
 
      11-11-2006
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

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      11-11-2006
andrewzzz wrote:
> how do i convert an hash map into a byte array(being able to restore
> this later , without losing data)?


Serialization !

Arne
 
Reply With Quote
 
 
 
 
andrewzzz
Guest
Posts: n/a
 
      11-11-2006


On 11 Nov, 20:39, Arne Vajhøj <a...@vajhoej.dk> wrote:
> andrewzzz wrote:
> > 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!

 
Reply With Quote
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      11-11-2006
andrewzzz wrote:
> On 11 Nov, 20:39, Arne Vajhøj <a...@vajhoej.dk> wrote:
>> andrewzzz wrote:
>>> 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
 
Reply With Quote
 
andrewzzz
Guest
Posts: n/a
 
      11-11-2006


On 11 Nov, 20:53, Arne Vajhøj <a...@vajhoej.dk> wrote:
> andrewzzz wrote:
> > On 11 Nov, 20:39, Arne Vajhøj <a...@vajhoej.dk> wrote:
> >> andrewzzz wrote:
> >>> 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




thanks so much! I will try now!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PSD to XHTML Conversion Services and PSD to HTML CSS ConversionServices, PSD to Joomla, Drupal, Wordpress Conversion xhtml champs Python 0 06-21-2011 11:59 AM
PSD to XHTML Conversion Services and PSD to HTML CSS ConversionServices, PSD to Joomla, Drupal, Wordpress Conversion PSD to XHTML Conversion Services and PSD to HTML CSS Conversion Services, PSD to Joomla, Drupal, Wor VHDL 0 04-25-2011 06:43 AM
reuse HashMap$Entry (or HashMap in total) to avoid millions of allocations Vince Darley Java 4 03-02-2010 07:48 AM
conversion operator and conversion ctor subramanian100in@yahoo.com, India C++ 2 09-15-2009 12:46 PM
java.util.Properties extending from HashMap<Object, Object> insteadof HashMap<String, String> Rakesh Java 10 04-08-2008 04:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57