|
LimeWire Collection Component API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.limewire.collection.ByteArrayCache
public class ByteArrayCache
A cache of byte[]. Sets a limit to the number of byte arrays that can be
created. ByteArrayCache has methods to create and release the
byte arrays, as well as check the size (total size, remaining size, and byte
array size).
When the maximum number of byte arrays are created (getCreated() ==
getMaxSize()), attempts to get a new byte array (get())
block until a byte array is freed (release(byte[])).
ByteArrayCache bac = new ByteArrayCache(3, 2);
byte[] b1 = bac.getQuick();
byte[] b2 = bac.getQuick();
for(int i = 0; i < b1.length; i++)
b1[i] = 1;
System.arraycopy(b1, 0, b2, 0, b1.length);
for(int i = 0; i < b2.length; i++)
System.out.println("b2[" + i + "]: " + b2[i]);
Output:
b2[0]: 1
b2[1]: 1
| Constructor Summary | |
|---|---|
ByteArrayCache()
Constructs a new ByteArraCache using the default size of 512 & length of 1024 |
|
ByteArrayCache(int maxSize,
int length)
Constructs a new ByteArrayCache using the given maxSize & length. |
|
| Method Summary | |
|---|---|
void |
clear()
Clears all items in the cache. |
byte[] |
get()
Attempts to retrieve a new byte[]. |
int |
getCacheSize()
Returns the size of all cached bytes. |
int |
getCreated()
Returns the number of byte[]'s this cache has created. |
int |
getLength()
Returns the length of the byte[]'s this creates. |
int |
getMaxSize()
Returns the maximum number of byte[]'s this will create. |
byte[] |
getQuick()
Attempts to retrieve a new byte[]. |
boolean |
isBufferAvailable()
Determines if there's space in the cache for another byte[]. |
void |
release(byte[] data)
Returns a byte[] to this cache. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ByteArrayCache()
public ByteArrayCache(int maxSize,
int length)
| Method Detail |
|---|
public int getCacheSize()
public byte[] get()
throws InterruptedException
InterruptedExceptionpublic byte[] getQuick()
public void release(byte[] data)
public void clear()
public boolean isBufferAvailable()
public int getCreated()
public int getLength()
public int getMaxSize()
|
LimeWire Collection Component API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||