public void testBiggerByteArray() throws Exception
    {
        int bufSize = 256;
        boolean numeric = false;
        Schema<PojoWithBiggerByteArray> schema = SCHEMA;

        PojoWithBiggerByteArray message = new PojoWithBiggerByteArray();
        message.id = 1;
        message.b = new byte[bufSize * 3];
        for (int i = 0; i < message.b.length; i++)
            message.b[i] = (byte) (i % message.b.length);

        message.ts = System.currentTimeMillis();

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        LinkedBuffer buffer = LinkedBuffer.allocate(bufSize);
        final KvpOutput output = new KvpOutput(buffer, out, schema, numeric);
        try
        {
            schema.writeTo(output, message);
            LinkedBuffer.writeTo(out, buffer);
        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a byte array threw an IOException " +
                    "(should never happen).", e);
        }
        byte[] data = out.toByteArray();

        PojoWithBiggerByteArray m2 = new PojoWithBiggerByteArray();

        ByteArrayInputStream in = new ByteArrayInputStream(data, 0, data.length);
        try
        {
            schema.mergeFrom(new KvpInput(in, new byte[bufSize], numeric), m2);
        }
        catch (ArrayIndexOutOfBoundsException e)
        {
            throw new ProtostuffException("Truncated message.", e);
        }

        assertEquals(message, m2);
    }
A test for deserializing byte array fields that exceed the input's buffer size.

@author David Yu
@created Jun 21, 2011
protostuff-kvp/src/test/java/io/protostuff/KvpByteArrayTest.java