@SuppressWarnings("unchecked")
    public <TCOSBase extends COSBase> TCOSBase cloneForNewDocument(TCOSBase base) throws IOException
    {
        if (base == null)
        {
            return null;
        }
        COSBase retval = clonedVersion.get(base);
        if (retval != null)
        {
            // we are done, it has already been converted.
            return (TCOSBase) retval;
        }
        if (clonedValues.contains(base))
        {
            // Don't clone a clone
            return base;
        }
        retval = cloneCOSBaseForNewDocument(base);
        clonedVersion.put(base, retval);
        clonedValues.add(retval);
        return (TCOSBase) retval;
    }
@Test
    void testClonePDFWithCosArrayStream() throws IOException
    {
        try (PDDocument srcDoc = new PDDocument();
             PDDocument dstDoc = new PDDocument())
        {

            PDPage pdPage = new PDPage();
            srcDoc.addPage(pdPage);
            new PDPageContentStream(srcDoc, pdPage, AppendMode.APPEND, true).close();
            new PDPageContentStream(srcDoc, pdPage, AppendMode.APPEND, true).close();
            new PDFCloneUtility(dstDoc).cloneForNewDocument(pdPage.getCOSObject());
        }
    }