V - type of SimpleDataStructure objects cachedpublic class SDSCache<V extends SimpleDataStructure> extends Object
private static final SDSCache< Foo> _cache = new SDSCache(Foo.class, LENGTH, 1024);
public static Foo create(byte[] data) {
return _cache.get(data);
}
public static Foo create(byte[] data, int off) {
return _cache.get(data, off);
}
public static Foo create(InputStream in) throws IOException {
return _cache.get(in);
}
| Constructor and Description |
|---|
SDSCache(Class<V> rvClass,
int len,
int max)Class that we are storing, i.e. |
| Modifier and Type | Method and Description |
|---|---|
void | clear()Clear all entries from the cache. |
V | get(byte[] data)WARNING - If the SDS is found in the cache, the passed-in
byte array will be returned to the SimpleByteCache for reuse. |
V | get(byte[] b,
int off)Non-null byte array containing the data, data will be copied to not hold the reference. |
V | get(InputStream in)Stream from which the bytes will be read. |
public SDSCache(Class<V> rvClass, int len, int max)
rvClass - the class that we are storing, i.e. an extension of SimpleDataStructurelen - the length of the byte array in the SimpleDataStructuremax - maximum size of the cache assuming 128MB of mem.
The actual max size will be scaled based on available memory.public void clear()
public V get(byte[] data)
data - non-null, the byte array for the SimpleDataStructureIllegalArgumentException - if data is not the correct number of bytesNullPointerException - if data is nullpublic V get(byte[] b, int off)
b - non-null byte array containing the data, data will be copied to not hold the referenceoff - offset in the array to start reading fromArrayIndexOutOfBoundsException - if not enough bytesNullPointerExceptionpublic V get(InputStream in) throws IOException
in - a stream from which the bytes will be readIOException - if not enough bytes