1 | // Copyright (c) 2006 Dustin Sallings <dustin@spy.net> |
2 | |
3 | package net.spy.memcached; |
4 | |
5 | import java.util.Arrays; |
6 | |
7 | /** |
8 | * Cached data with its attributes. |
9 | */ |
10 | public final class CachedData { |
11 | |
12 | /** |
13 | * Maximum data size allowed by memcached. |
14 | */ |
15 | public static final int MAX_SIZE = 1024*1024; |
16 | |
17 | private final int flags; |
18 | private final byte[] data; |
19 | |
20 | /** |
21 | * Get a CachedData instance for the given flags and byte array. |
22 | * |
23 | * @param f the flags |
24 | * @param d the data |
25 | * @param max_size the maximum allowable size. |
26 | */ |
27 | public CachedData(int f, byte[] d, int max_size) { |
28 | super(); |
29 | if(d.length > max_size) { |
30 | throw new IllegalArgumentException( |
31 | "Cannot cache data larger than " + max_size |
32 | + " bytes (you tried to cache a " |
33 | + d.length + " byte object)"); |
34 | } |
35 | flags=f; |
36 | data=d; |
37 | } |
38 | |
39 | /** |
40 | * Get the stored data. |
41 | */ |
42 | public byte[] getData() { |
43 | return data; |
44 | } |
45 | |
46 | /** |
47 | * Get the flags stored along with this value. |
48 | */ |
49 | public int getFlags() { |
50 | return flags; |
51 | } |
52 | |
53 | @Override |
54 | public String toString() { |
55 | return "{CachedData flags=" + flags + " data=" |
56 | + Arrays.toString(data) + "}"; |
57 | } |
58 | } |