FileDocCategorySizeDatePackage
PoolingByteArrayOutputStreamTest.javaAPI DocAndroid 5.1 API2604Thu Mar 12 22:22:56 GMT 2015com.android.volley.toolbox

PoolingByteArrayOutputStreamTest

public class PoolingByteArrayOutputStreamTest extends android.test.AndroidTestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestPooledIndividualWrites()

        ByteArrayPool pool = new ByteArrayPool(32768);
        writeBytesIndividually(pool);
        writeBytesIndividually(pool);
        writeBytesIndividually(pool);
    
public voidtestPooledOneBuffer()

        ByteArrayPool pool = new ByteArrayPool(32768);
        writeOneBuffer(pool);
        writeOneBuffer(pool);
        writeOneBuffer(pool);
    
public voidtestUnpooled()

        ByteArrayPool pool = new ByteArrayPool(0);
        writeOneBuffer(pool);
        writeOneBuffer(pool);
        writeOneBuffer(pool);
    
public voidtestUnpooledIndividualWrites()

        ByteArrayPool pool = new ByteArrayPool(0);
        writeBytesIndividually(pool);
        writeBytesIndividually(pool);
        writeBytesIndividually(pool);
    
private voidwriteBytesIndividually(ByteArrayPool pool)

        byte[] data = new byte[16384];
        for (int i = 0; i < data.length; i++) {
            data[i] = (byte) (i & 0xff);
        }
        PoolingByteArrayOutputStream os = new PoolingByteArrayOutputStream(pool);
        for (int i = 0; i < data.length; i++) {
            os.write(data[i]);
        }

        assertTrue(Arrays.equals(data, os.toByteArray()));
    
private voidwriteOneBuffer(ByteArrayPool pool)

        byte[] data = new byte[16384];
        for (int i = 0; i < data.length; i++) {
            data[i] = (byte) (i & 0xff);
        }
        PoolingByteArrayOutputStream os = new PoolingByteArrayOutputStream(pool);
        os.write(data);

        assertTrue(Arrays.equals(data, os.toByteArray()));