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,
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);
}
}
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[] !
> 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[].