public void encode(OutputContext ctx, ArrayList<?> v) throws IOException { final OutputStream os = ctx.getOutputStream(); int indexOfStoredObject = ctx.indexOfStoredObjects(v); if (indexOfStoredObject >= 0) { IntegerComponents ics = intComponents(indexOfStoredObject); os.write(0x80 | (ics.length << 5) | JMF_ARRAY_LIST); writeIntData(ctx, ics); } else { ctx.addToStoredObjects(v); Object[] snapshot = v.toArray(); IntegerComponents ics = intComponents(snapshot.length); os.write((ics.length << 5) | JMF_ARRAY_LIST); writeIntData(ctx, ics); for (Object element : snapshot) ctx.writeObject(element); } }