1 | package net.spy.memcached; |
2 | |
3 | import java.io.UnsupportedEncodingException; |
4 | import java.util.ArrayList; |
5 | import java.util.Collection; |
6 | |
7 | /** |
8 | * Utilities for processing key values. |
9 | */ |
10 | public class KeyUtil { |
11 | |
12 | /** |
13 | * Get the bytes for a key. |
14 | * |
15 | * @param k the key |
16 | * @return the bytes |
17 | */ |
18 | public static byte[] getKeyBytes(String k) { |
19 | try { |
20 | return k.getBytes("UTF-8"); |
21 | } catch (UnsupportedEncodingException e) { |
22 | throw new RuntimeException(e); |
23 | } |
24 | } |
25 | |
26 | /** |
27 | * Get the keys in byte form for all of the string keys. |
28 | * |
29 | * @param keys a collection of keys |
30 | * @return return a collection of the byte representations of keys |
31 | */ |
32 | public static Collection<byte[]> getKeyBytes(Collection<String> keys) { |
33 | Collection<byte[]> rv=new ArrayList<byte[]>(keys.size()); |
34 | for(String s : keys) { |
35 | rv.add(getKeyBytes(s)); |
36 | } |
37 | return rv; |
38 | } |
39 | } |