cache byte[]

Hi ,

I wanna save a byte array byte [] on a Hashtable.

The byte array is a DatagramPacket capture.

If I receive a request matching the saved byte array , I wanna get the DatagramPacket from the Hashtable.

But I have Object to byte[] convertion trouble ...

Who can help please.

Thanks,

[327 byte] By [ballanianga] at [2007-11-27 10:52:31]
# 1

import java.util.Map;

import java.util.HashMap;

class Test {

public static void main(String[] argv) {

Map<String, byte[]> mystuff = new HashMap<String, byte[]>();

byte[] first = { 1, 2, 3, 4, 5 };

byte[] second = { 6, 7, 8, 9, 10 };

mystuff.put("first", first);

mystuff.put("second", second);

byte[] wowee = mystuff.get("first");

byte[] awesome = mystuff.get("second");

for( byte b : wowee ) System.out.println(b);

for( byte b : awesome) System.out.println(b);

}

}

Navy_Codera at 2007-7-29 11:38:01 > top of Java-index,Java Essentials,Java Programming...
# 2

Thanks for your code it works very well.

But if I retrieve the byte[] from the hashmap and send it to the client the format (DNS) seems not to be valid. It looks like the hashmap do some kind of transformation on my byte[] !

ballanianga at 2007-7-29 11:38:01 > top of Java-index,Java Essentials,Java Programming...
# 3

> Thanks for your code it works very well.

> But if I retrieve the byte[] from the hashmap and

> send it to the client the format (DNS) seems not to

> be valid. It looks like the hashmap do some kind of

> transformation on my byte[] !

The HashMap isn't doing anything to your byte[].

Navy_Codera at 2007-7-29 11:38:01 > top of Java-index,Java Essentials,Java Programming...