FileDocCategorySizeDatePackage
BufferCache.javaAPI DocJCIFS 1.3.17 API2356Tue Oct 18 15:26:24 BST 2011jcifs.smb

BufferCache

public class BufferCache extends Object

Fields Summary
private static final int
MAX_BUFFERS
static Object[]
cache
private static int
freeBuffers
Constructors Summary
Methods Summary
public static byte[]getBuffer()


        
        synchronized( cache ) {
            byte[] buf;

            if (freeBuffers > 0) {
                for (int i = 0; i < MAX_BUFFERS; i++) {
                    if( cache[i] != null ) {
                        buf = (byte[])cache[i];
                        cache[i] = null;
                        freeBuffers--;
                        return buf;
                    }
                }
            }

            buf = new byte[SmbComTransaction.TRANSACTION_BUF_SIZE];

            return buf;
        }
    
static voidgetBuffers(SmbComTransaction req, SmbComTransactionResponse rsp)

        synchronized( cache ) {
            req.txn_buf = getBuffer();
            rsp.txn_buf = getBuffer();
        }
    
public static voidreleaseBuffer(byte[] buf)

        synchronized( cache ) {
            if (freeBuffers < MAX_BUFFERS) {
                for (int i = 0; i < MAX_BUFFERS; i++) {
                    if (cache[i] == null) {
                        cache[i] = buf;
                        freeBuffers++;
                        return;
                    }
                }
            }
        }