com.android.volley.toolbox.ByteArrayPool Java Examples

The following examples show how to use com.android.volley.toolbox.ByteArrayPool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StreamBasedNetwork.java    From RestVolley with Apache License 2.0 5 votes vote down vote up
/** Reads the contents of HttpEntity into a byte[]. */
public static byte[] entityToBytes(InputStream inputStream, long contentLength, int bufferSize) throws IOException, ServerError {
    ByteArrayPool bytePool = new ByteArrayPool(bufferSize);
    PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(bytePool, (int)contentLength);
    byte[] buffer = null;
    try {
        if (inputStream == null) {
            throw new ServerError();
        }
        buffer = bytePool.getBuf(1024);
        int count;
        while ((count = inputStream.read(buffer)) != -1) {
            bytes.write(buffer, 0, count);
        }
        return bytes.toByteArray();
    } finally {
        try {
            // Close the InputStream and release the resources by "consuming the content".
            inputStream.close();
        } catch (IOException e) {
            // This can happen if there was an exception above that left the entity in
            // an invalid state.
            VolleyLog.v("Error occured when calling consumingContent");
        }
        bytePool.returnBuf(buffer);
        bytes.close();
    }
}
 
Example #2
Source File: RVNetwork.java    From RestVolley with Apache License 2.0 4 votes vote down vote up
/**
 * @param httpStack HTTP stack to be used
 */
public RVNetwork(HttpStack httpStack) {
    // If a pool isn't passed in, then build a small default pool that will give us a lot of
    // benefit and not use too much memory.
    this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE));
}
 
Example #3
Source File: RVNetwork.java    From RestVolley with Apache License 2.0 4 votes vote down vote up
/**
 * @param httpStack HTTP stack to be used
 * @param pool a buffer pool that improves GC performance in copy operations
 */
public RVNetwork(HttpStack httpStack, ByteArrayPool pool) {
    mHttpStack = httpStack;
    mPool = pool;
}
 
Example #4
Source File: OkNetwork.java    From OkVolley with Apache License 2.0 4 votes vote down vote up
/**
 * @param httpStack HTTP stack to be used
 */
public OkNetwork(OkStack httpStack) {
    // If a pool isn't passed in, then build a small default pool that will give us a lot of
    // benefit and not use too much memory.
    this(httpStack, new ByteArrayPool(DEFAULT_POOL_SIZE));
}
 
Example #5
Source File: OkNetwork.java    From OkVolley with Apache License 2.0 4 votes vote down vote up
/**
 * @param httpStack HTTP stack to be used
 * @param pool      a buffer pool that improves GC performance in copy operations
 */
public OkNetwork(OkStack httpStack, ByteArrayPool pool) {
    mHttpStack = httpStack;
    mPool = pool;
}
 
Example #6
Source File: FileRequest.java    From CrossBow with Apache License 2.0 4 votes vote down vote up
public void setByteArrayPool(ByteArrayPool byteArrayPool) {
    this.byteArrayPool = byteArrayPool;
}
 
Example #7
Source File: JacksonNetwork.java    From volley-jackson-extension with Apache License 2.0 2 votes vote down vote up
/**
 * @param httpStack The HTTP stack that requests are performed with.
 * @param poolSize The size of the pool buffer used for cached requests. NOTE: caching
 *                 requests will have a significant adverse affect on parsing speed!
 */
public JacksonNetwork(HttpStack httpStack, int poolSize) {
	mHttpStack = httpStack;
	mPool = new ByteArrayPool(poolSize);
}