/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter Unisharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

package com.pullenti.unitext.internal.pdf;

public class PdfDictionary extends PdfObject {

    private java.util.HashMap<String, PdfObject> m_Items = new java.util.HashMap<String, PdfObject>();

    private byte[] m_StreamData = null;

    private PdfStream m_StreamIn = null;

    private int m_StreamPos = 0;

    private int m_StreamLength = 0;

    public int m_FilePos;

    public int pageNum;

    public byte[] getData() throws java.io.IOException {
        if (m_StreamData == null) {
            if (m_StreamLength == 0) 
                return null;
            m_StreamData = new byte[m_StreamLength];
            m_StreamIn.setPosition(m_StreamPos);
            m_StreamIn.read(m_StreamData, 0, m_StreamLength);
        }
        return m_StreamData;
    }

    public void setData(byte[] dat) {
        m_StreamData = dat;
    }

    public void addObject(String key, PdfObject o) {
        if (!m_Items.containsKey(key)) {
            if (o != null) 
                m_Items.put(key, o);
        }
        else if (o != null) 
            m_Items.put(key, o);
        else 
            m_Items.remove(key);
    }

    public java.util.ArrayList<String> getKeys() {
        return new java.util.ArrayList<String>(m_Items.keySet());
    }


    @Override
    public boolean isSimple(int lev) throws java.io.IOException {
        if (m_Items.size() > 10 || lev > 10) 
            return false;
        for (String key : getKeys()) {
            if (com.pullenti.unisharp.Utils.stringsEq(key, "Parent")) 
                continue;
            PdfObject it = this.getObject(key, false);
            if (it != null && !it.isSimple(lev + 1)) 
                return false;
        }
        return true;
    }

    @Override
    public String toStringEx(int lev) throws java.io.IOException {
        if (lev > 5) 
            return ("<<..." + m_Items.size() + ">>");
        StringBuilder res = new StringBuilder();
        PdfObject it = this.getObject("Type", false);
        if (it != null && lev >= 0) 
            res.append(it.toString());
        if (pageNum > 0) 
            res.append(" Num=").append(pageNum);
        if (id > 0) 
            res.append(" Id=").append(id);
        res.append("<<");
        boolean fi = true;
        boolean partial = false;
        for (String key : getKeys()) {
            if (com.pullenti.unisharp.Utils.stringsEq(key, "Parent") || com.pullenti.unisharp.Utils.stringsEq(key, "Type")) 
                continue;
            it = this.getObject(key, false);
            if (it == null) {
                PdfObject indir = m_Items.get(key);
                if (!fi) 
                    res.append(", ");
                else 
                    fi = false;
                res.append(key).append("=").append((indir == null ? "NULL" : indir.toString()));
                if (res.length() > 100) 
                    break;
                continue;
            }
            if (!it.isSimple(lev + 1)) {
                partial = true;
                continue;
            }
            if (!fi) 
                res.append(", ");
            else 
                fi = false;
            if (res.length() > 100) {
                partial = true;
                break;
            }
            String str = it.toStringEx(lev + 1);
            if (str.length() > 50) 
                str = str.substring(0, 0 + 50) + "...";
            res.append(key).append("=").append(str);
        }
        if (partial) 
            res.append("...").append(m_Items.size());
        res.append(">>");
        if (m_StreamLength > 0) 
            res.append(" DATA:").append(m_StreamLength);
        return res.toString();
    }

    @Override
    public void outHtml(StringBuilder res) throws java.io.IOException, Exception, java.io.FileNotFoundException {
        if (id > 0) 
            res.append("Id=").append(id).append(" ");
        res.append("<b>&lt;&lt;</b> ");
        boolean fi = true;
        for (String k : getKeys()) {
            if (fi) 
                fi = false;
            else 
                res.append(", <br/>");
            res.append(k).append(" : ");
            PdfObject o = this.getObject(k, false);
            if (o == null) {
                res.append("null");
                continue;
            }
            if (o.id > 0) {
                res.append("<a href=\"obj").append(o.id).append("\">");
                com.pullenti.util.MiscHelper.correctHtmlValue(res, o.toString(), false, false, false);
                res.append("</a>");
            }
            else 
                o.outHtml(res);
        }
        res.append("<b> &gt;&gt;</b>");
        this._outHtmlRefs(res);
        PdfPage page = null;
        if (this.isTypeItem("Page")) 
            page = new PdfPage(this, null, true, false);
        else if (this.isTypeItem("XObject") && com.pullenti.unisharp.Utils.stringsEq(this.getStringItem("Subtype"), "Form")) {
            java.util.ArrayList<PdfObject> li = sourceFile.getAllWhoRefObject0(id);
            for (PdfObject o : li) {
                if ((o instanceof PdfDictionary) && ((PdfDictionary)com.pullenti.unisharp.Utils.cast(o, PdfDictionary.class)).isTypeItem("Page")) {
                    PdfPage page0 = new PdfPage((PdfDictionary)com.pullenti.unisharp.Utils.cast(o, PdfDictionary.class), null, true, false);
                    if (page0.subpages != null) {
                        for (PdfPage p : page0.subpages) {
                            if (p.getDic() == this) {
                                page = p;
                                break;
                            }
                        }
                    }
                    break;
                }
            }
        }
        if (page != null && page.lexems != null) {
            res.append("\r\n<br/><hr/>");
            java.util.ArrayList<PdfPageOper> opers = PdfPageOper.parse(page.lexems);
            for (PdfPageOper op : opers) {
                op.outHtml(res);
                res.append("<br/>");
            }
        }
        else if (this.isTypeItem("Font")) {
            res.append("\r\n<br/><hr/>");
            PdfFont font = new PdfFont(this);
            com.pullenti.util.MiscHelper.correctHtmlValue(res, font.outDebug(), false, false, false);
        }
        else if (this.isTypeItem("Image") || ((this.isTypeItem("XObject") && com.pullenti.unisharp.Utils.stringsEq(this.getStringItem("Subtype"), "Image")))) {
            res.append("\r\n<br/><hr/>");
            PdfImage img = new PdfImage(this, false, null, false);
            if (img.content != null) {
                com.pullenti.unitext.FileFormat frm = com.pullenti.util.FileFormatsHelper.analizeFormat(null, img.content);
                res.append("<div>Image Format: <b>").append(frm.toString()).append("</b></div>");
                com.pullenti.unitext.UnitextImage uimg = new com.pullenti.unitext.UnitextImage();
                uimg.content = img.content;
                if (img.getWidth() > 0) 
                    uimg.width = ((((Integer)((int)img.getWidth())).toString()) + "pt");
                if (img.getHeight() > 0) 
                    uimg.height = ((((Integer)((int)img.getHeight())).toString()) + "pt");
                res.append("<div style=\"border:1pt solid red\">");
                uimg.getHtml(res, null);
                res.append("</div>");
            }
        }
        else if (getHasDataStream()) {
            res.append("\r\n<br/><hr/>DataStream:<br/>");
            try {
                byte[] dat = this.extractData();
                if (dat == null) 
                    dat = this.getData();
                if (dat != null) {
                    int hasZero = 0;
                    int zind = -1;
                    for (int i = 0; i < dat.length; i++) {
                        if (dat[i] == ((byte)0)) {
                            hasZero++;
                            if (zind < 0) 
                                zind = i;
                            break;
                        }
                    }
                    if ((hasZero < 3) || zind > 1000) {
                        int len = dat.length;
                        if (dat.length > 30000) 
                            len = 30000;
                        char ch0 = (char)0;
                        char ch1 = (char)1;
                        String txt = com.pullenti.unisharp.Utils.decodeCharset(java.nio.charset.Charset.forName("ASCII"), dat, 0, len).replace((String.valueOf(ch0)), "{0}").replace((String.valueOf(ch1)), "{1}");
                        com.pullenti.util.MiscHelper.correctHtmlValue(res, txt, false, false, false);
                    }
                    else {
                        res.append("<div style=\"font-family:monospace\">");
                        for (int i = 0; (i < dat.length) && (i < 1000); i++) {
                            if (((i & 0xF)) == 0) 
                                res.append("\n<br/>");
                            res.append(String.format("%02X", dat[i])).append(" ");
                            if (res.length() > 30000) {
                                res.append("\r\n<br/>...");
                                break;
                            }
                        }
                        res.append("</div>");
                    }
                }
            } catch (Exception ex) {
                res.append("ERROR: ");
                com.pullenti.util.MiscHelper.correctHtmlValue(res, ex.toString(), false, false, false);
            }
        }
    }

    public boolean getHasDataStream() {
        return m_StreamLength > 0;
    }


    public void postParse(PdfStream stream) throws java.io.IOException {
        m_Items.clear();
        m_StreamIn = null;
        m_StreamLength = 0;
        m_StreamData = null;
        int p0 = stream.getPosition();
        byte ch;
        int i;
        String str;
        while ((((i = stream.peekSolidByte()))) >= 0) {
            ch = (byte)i;
            if (((char)ch) == '/') {
                str = PdfStringValue.getStringByBytes(stream.readName());
                if (str == null) 
                    break;
                if (com.pullenti.unisharp.Utils.stringsEq(str, "Contents")) {
                }
                PdfObject _obj = stream.parseObject(sourceFile, false);
                if (_obj == null) 
                    break;
                if (!m_Items.containsKey(str)) 
                    m_Items.put(str, _obj);
                continue;
            }
            if (((char)ch) != '>') 
                break;
            stream.setPosition(stream.getPosition() + 1);
            ch = (byte)stream.readByte();
            if (((char)ch) != '>') 
                break;
            this._parseStream(stream);
            return;
        }
    }

    private void _parseStream(PdfStream stream) throws java.io.IOException {
        int p0 = stream.getPosition();
        String str = stream.readWord(false);
        if (com.pullenti.unisharp.Utils.stringsNe(str, "stream")) {
            stream.setPosition(p0);
            return;
        }
        byte[] streamTag = new byte[6];
        byte ch = (byte)stream.readByte();
        if (ch != ((byte)0xD)) 
            stream.setPosition(stream.getPosition() - 1);
        ch = (byte)stream.readByte();
        if (ch != ((byte)0xA)) 
            stream.setPosition(stream.getPosition() - 1);
        m_StreamIn = stream;
        m_StreamPos = stream.getPosition();
        m_StreamLength = this.getIntItem("Length");
        if (m_StreamLength > 0 && ((m_StreamPos + m_StreamLength) < stream.getLength())) 
            stream.setPosition(m_StreamPos + m_StreamLength);
        int len = 0;
        int i;
        while ((((i = stream.readByte()))) >= 0) {
            ch = (byte)i;
            len++;
            if (((char)ch) != 'e') 
                continue;
            ch = (byte)stream.readByte();
            len++;
            if (((char)ch) != 'n') 
                continue;
            ch = (byte)stream.readByte();
            len++;
            if (((char)ch) != 'd') 
                continue;
            p0 = stream.getPosition();
            stream.read(streamTag, 0, 6);
            if (com.pullenti.unisharp.Utils.stringsEq(PdfStringValue.getStringByBytes(streamTag), "stream")) {
                len -= 3;
                break;
            }
            stream.setPosition(p0);
        }
        if (m_StreamLength == 0) 
            m_StreamLength = len;
    }

    public String getStringItem(String key) throws java.io.IOException {
        PdfObject val = this.getObject(key, false);
        while (true) {
            if (val == null) 
                return null;
            if (val instanceof PdfName) 
                return ((PdfName)com.pullenti.unisharp.Utils.cast(val, PdfName.class)).name;
            if (val instanceof PdfBoolValue) 
                return (((PdfBoolValue)com.pullenti.unisharp.Utils.cast(val, PdfBoolValue.class)).val ? "true" : "false");
            if (val instanceof PdfStringValue) 
                return PdfStringValue.getStringByBytes(((PdfStringValue)com.pullenti.unisharp.Utils.cast(val, PdfStringValue.class)).val);
            if (val instanceof PdfIntValue) 
                return ((Integer)((PdfIntValue)com.pullenti.unisharp.Utils.cast(val, PdfIntValue.class)).val).toString();
            if (val instanceof PdfArray) {
                val = ((PdfArray)com.pullenti.unisharp.Utils.cast(val, PdfArray.class)).getItem(0, false);
                if (val == null) 
                    break;
                continue;
            }
            break;
        }
        return null;
    }

    public boolean isTypeItem(String typeVal) throws java.io.IOException {
        return com.pullenti.unisharp.Utils.stringsEq(this.getStringItem("Type"), typeVal);
    }

    public int getIntItem(String key) throws java.io.IOException {
        PdfObject val = this.getObject(key, false);
        if (val == null) 
            return 0;
        if (val instanceof PdfIntValue) 
            return ((PdfIntValue)com.pullenti.unisharp.Utils.cast(val, PdfIntValue.class)).val;
        if (val instanceof PdfRealValue) 
            return (int)((PdfRealValue)com.pullenti.unisharp.Utils.cast(val, PdfRealValue.class)).getDouble();
        return 0;
    }

    public PdfObject getObject(String key, boolean keepRef) throws java.io.IOException {
        PdfObject res = null;
        com.pullenti.unisharp.Outargwrapper<PdfObject> wrapres176 = new com.pullenti.unisharp.Outargwrapper<PdfObject>();
        boolean inoutres177 = com.pullenti.unisharp.Utils.tryGetValue(m_Items, key, wrapres176);
        res = wrapres176.value;
        if (!inoutres177) 
            return null;
        if ((res instanceof PdfReference) && !keepRef) {
            res = sourceFile.getObject(res.id);
            if (res == null) 
                return null;
            m_Items.put(key, res);
        }
        return res;
    }

    public PdfDictionary getDictionary(String key, String typVal) throws java.io.IOException {
        PdfObject _obj = this.getObject(key, false);
        if (_obj instanceof PdfArray) 
            _obj = ((PdfArray)com.pullenti.unisharp.Utils.cast(_obj, PdfArray.class)).getItem(0, false);
        if (_obj instanceof PdfDictionary) {
            PdfDictionary res = (PdfDictionary)com.pullenti.unisharp.Utils.cast(_obj, PdfDictionary.class);
            if (typVal != null) {
                if (!res.isTypeItem(typVal)) 
                    return null;
            }
            return res;
        }
        return null;
    }

    public void getAllPages(java.util.ArrayList<PdfDictionary> res) throws java.io.IOException {
        if (this.isTypeItem("Page")) {
            res.add(this);
            return;
        }
        PdfDictionary dic = this.getDictionary("Pages", "Pages");
        if (dic != null) 
            dic.getAllPages(res);
        else {
            PdfArray kids = (PdfArray)com.pullenti.unisharp.Utils.cast(this.getObject("Kids", false), PdfArray.class);
            if (kids != null) {
                for (int i = 0; i < kids.getItemsCount(); i++) {
                    PdfObject it = kids.getItem(i, false);
                    if (it instanceof PdfDictionary) 
                        ((PdfDictionary)com.pullenti.unisharp.Utils.cast(it, PdfDictionary.class)).getAllPages(res);
                }
            }
        }
    }

    public byte[] extractData() throws java.io.IOException, Exception {
        byte[] dat = this.getData();
        if (dat == null) 
            return new byte[0];
        String str = this.getStringItem("Filter");
        if (com.pullenti.unisharp.Utils.isNullOrEmpty(str)) 
            return dat;
        if (dat.length < 10) 
            return null;
        byte[] res = null;
        if (com.pullenti.unisharp.Utils.stringsEq(str, "FlateDecode")) 
            res = com.pullenti.util.ArchiveHelper.decompressZlib(dat);
        else if (com.pullenti.unisharp.Utils.stringsEq(str, "LZWDecode")) {
            com.pullenti.unitext.internal.misc.LzwDecoder lzw = new com.pullenti.unitext.internal.misc.LzwDecoder();
            res = lzw.decode(dat);
        }
        else 
            return null;
        if (res == null || res.length == 0) 
            return null;
        PdfDictionary dparms = this.getDictionary("DecodeParms", null);
        int predict = 0;
        int N = 0;
        int columns = 0;
        if (dparms != null) {
            PdfIntValue iv = (PdfIntValue)com.pullenti.unisharp.Utils.cast(dparms.getObject("Predictor", false), PdfIntValue.class);
            if (iv != null && iv.val > 1) 
                predict = iv.val;
            iv = (PdfIntValue)com.pullenti.unisharp.Utils.cast(dparms.getObject("Columns", false), PdfIntValue.class);
            if (iv != null) 
                columns = iv.val;
            iv = (PdfIntValue)com.pullenti.unisharp.Utils.cast(dparms.getObject("Colors", false), PdfIntValue.class);
            if (iv != null) 
                N = iv.val;
        }
        if ((predict >= 10 && predict <= 15 && N > 0) && columns > 0) {
            int rowSize = columns * N;
            if (predict == 15) 
                rowSize += 1;
            for (int pos0 = 0; (pos0 + rowSize) < res.length; pos0 += rowSize) {
                int cod = predict - 10;
                int pos = pos0;
                if (predict == 15) {
                    cod = Byte.toUnsignedInt(res[pos0]);
                    pos++;
                }
                for (int j = pos; j < (pos0 + rowSize); j++) {
                    byte valLeft = (byte)0;
                    byte valTop = (byte)0;
                    byte valCorner = (byte)0;
                    int k = j - N;
                    int kk = j - rowSize;
                    if (kk >= 0) 
                        valTop = res[kk];
                    if (k >= pos) {
                        valLeft = res[k];
                        if (kk >= 0) 
                            valCorner = res[kk - N];
                    }
                    res[j] = com.pullenti.unitext.internal.misc.PngWrapper.filterByte(cod, false, res[j], valLeft, valTop, valCorner);
                }
            }
            if (predict == 15) {
                int p = 0;
                for (int i = 0; i < res.length; i++) {
                    if (((i % rowSize)) == 0) {
                    }
                    else {
                        res[p] = res[i];
                        p++;
                    }
                }
                com.pullenti.unisharp.Outargwrapper<byte[]> wrapres178 = new com.pullenti.unisharp.Outargwrapper<byte[]>(res);
                wrapres178.value = java.util.Arrays.copyOf(wrapres178.value, p);
                res = wrapres178.value;
            }
        }
        return res;
    }

    public void setDataValue(byte[] data) throws Exception, java.io.IOException {
        PdfName filt = (PdfName)com.pullenti.unisharp.Utils.cast(this.getObject("Filter", false), PdfName.class);
        if (filt != null) {
            if (com.pullenti.unisharp.Utils.stringsEq(filt.name, "FlateDecode") || com.pullenti.unisharp.Utils.stringsEq(filt.name, "LZWDecode")) {
                filt.name = "FlateDecode";
                data = com.pullenti.util.ArchiveHelper.compressZlib(data);
            }
        }
        m_StreamData = data;
    }

    public byte[] getTotalDataStream(String key) throws java.io.IOException, Exception {
        PdfObject _obj = this.getObject(key, false);
        if (_obj == null) 
            return null;
        if (_obj instanceof PdfDictionary) 
            return ((PdfDictionary)_obj).extractData();
        PdfArray arr = (PdfArray)com.pullenti.unisharp.Utils.cast(_obj, PdfArray.class);
        if (arr == null) 
            return null;
        java.util.ArrayList<Byte> res = null;
        for (int i = 0; i < arr.getItemsCount(); i++) {
            _obj = arr.getItem(i, false);
            if (_obj == null) 
                continue;
            if (!(_obj instanceof PdfDictionary)) 
                continue;
            byte[] tmp = ((PdfDictionary)_obj).extractData();
            if (tmp == null) 
                continue;
            if (tmp.length < 1) 
                continue;
            if (res == null) 
                res = new java.util.ArrayList<Byte>(java.util.Arrays.asList(com.pullenti.unisharp.Utils.toBytesArrayObj(tmp)));
            else {
                res.add((byte)0xD);
                res.add((byte)0xA);
                com.pullenti.unisharp.Utils.addToArrayList(res, java.util.Arrays.asList(com.pullenti.unisharp.Utils.toBytesArrayObj(tmp)));
            }
        }
        if (res == null) 
            return null;
        return com.pullenti.unisharp.Utils.toBytesArray(res.toArray(new Byte[res.size()]));
    }

    public void clearTotalDataStream(String key) throws java.io.IOException {
        PdfObject _obj = this.getObject(key, false);
        if (_obj == null) 
            return;
        if (_obj instanceof PdfDictionary) 
            ((PdfDictionary)_obj).setData(null);
        PdfArray arr = (PdfArray)com.pullenti.unisharp.Utils.cast(_obj, PdfArray.class);
        if (arr == null) 
            return;
        for (int i = 0; i < arr.getItemsCount(); i++) {
            _obj = arr.getItem(i, false);
            if (_obj == null) 
                continue;
            if (!(_obj instanceof PdfDictionary)) 
                continue;
            ((PdfDictionary)_obj).setData(null);
        }
    }

    @Override
    public void write(com.pullenti.unisharp.Stream s) throws java.io.IOException {
        if (id == 18) {
        }
        s.write((byte)'<');
        s.write((byte)'<');
        byte[] buf;
        boolean fi = true;
        byte[] dat = this.getData();
        boolean hasSize = false;
        if (dat != null) {
            if (dat.length == 448) {
            }
        }
        for (java.util.Map.Entry<String, PdfObject> kp : m_Items.entrySet()) {
            PdfObject it = kp.getValue();
            if (it.deleted) 
                continue;
            if (com.pullenti.unisharp.Utils.stringsEq(kp.getKey(), "Length") && dat != null && (it instanceof PdfIntValue)) {
                hasSize = true;
                ((PdfIntValue)com.pullenti.unisharp.Utils.cast(it, PdfIntValue.class)).val = dat.length;
            }
            if (fi) 
                fi = false;
            else 
                s.write((byte)' ');
            buf = com.pullenti.unisharp.Utils.encodeCharset(java.nio.charset.Charset.forName("ASCII"), ("/" + kp.getKey()));
            s.write(buf, 0, buf.length);
            s.write((byte)' ');
            if (it.id == 0 || com.pullenti.unisharp.Utils.stringsEq(kp.getKey(), "Length")) 
                it.write(s);
            else {
                buf = com.pullenti.unisharp.Utils.encodeCharset(java.nio.charset.Charset.forName("ASCII"), (((Integer)it.getWriteId()).toString() + " 0 R"));
                s.write(buf, 0, buf.length);
            }
        }
        if (!hasSize && dat != null) {
            if (fi) 
                fi = false;
            else 
                s.write((byte)' ');
            buf = com.pullenti.unisharp.Utils.encodeCharset(java.nio.charset.Charset.forName("ASCII"), ("/Length " + dat.length));
            s.write(buf, 0, buf.length);
        }
        s.write((byte)'>');
        s.write((byte)'>');
        if (dat == null) 
            return;
        buf = com.pullenti.unisharp.Utils.encodeCharset(java.nio.charset.Charset.forName("ASCII"), "stream\r\n");
        s.write(buf, 0, buf.length);
        s.write(dat, 0, dat.length);
        buf = com.pullenti.unisharp.Utils.encodeCharset(java.nio.charset.Charset.forName("ASCII"), "endstream");
        s.write(buf, 0, buf.length);
    }

    @Override
    public void getAllReferences(java.util.ArrayList<PdfReference> refs, java.util.ArrayList<Integer> ids) throws java.io.IOException {
        if (id > 0) {
            if (ids.contains(id)) 
                return;
            ids.add(id);
        }
        for (String k : getKeys()) {
            PdfObject o = this.getObject(k, true);
            if (o != null) 
                o.getAllReferences(refs, ids);
        }
        if (id > 0) 
            ids.remove(id);
    }

    @Override
    public void getAllWhoRefObject(int objId, PdfObject cur, java.util.ArrayList<PdfObject> res, java.util.ArrayList<Integer> ids) throws java.io.IOException {
        if (id > 0) {
            if (ids.contains(id)) 
                return;
            ids.add(id);
            cur = this;
        }
        for (String k : getKeys()) {
            PdfObject o = this.getObject(k, true);
            if (o != null && o.id == objId) {
                if (!res.contains(cur)) 
                    res.add(cur);
            }
            else if (o != null && o.id == 0) 
                o.getAllWhoRefObject(objId, cur, res, ids);
        }
        if (id > 0) 
            ids.remove(id);
    }

    public IPdfDictionaryWrapper obj;

    public void setNewDataContent(byte[] data) throws Exception, java.io.IOException {
        if (this.isTypeItem("XObject")) {
            this.setDataValue(data);
            return;
        }
        PdfObject cnts = this.getObject("Contents", false);
        if (cnts instanceof PdfDictionary) 
            ((PdfDictionary)com.pullenti.unisharp.Utils.cast(cnts, PdfDictionary.class)).setDataValue(data);
        else if (cnts instanceof PdfArray) {
            PdfArray arr = (PdfArray)com.pullenti.unisharp.Utils.cast(cnts, PdfArray.class);
            if (arr.getItemsCount() > 0) {
                PdfDictionary ddic = null;
                int len = 0;
                for (int i = 0; i < arr.getItemsCount(); i++) {
                    PdfDictionary cc = (PdfDictionary)com.pullenti.unisharp.Utils.cast(arr.getItem(i, false), PdfDictionary.class);
                    if (cc == null) 
                        continue;
                    int le = cc.getIntItem("Length");
                    if (le > len) {
                        len = le;
                        ddic = cc;
                    }
                }
                if (ddic != null) {
                    ddic.setDataValue(data);
                    for (int i = arr.getItemsCount() - 1; i >= 0; i--) {
                        PdfObject oo = arr.getItem(i, false);
                        if (oo != null && oo != ddic) 
                            oo.deleted = true;
                        if (oo != ddic) 
                            arr.removeItem(i);
                    }
                }
            }
        }
        else if (getHasDataStream()) 
            this.setDataValue(data);
        else {
        }
    }

    public static PdfDictionary _new245(int _arg1) {
        PdfDictionary res = new PdfDictionary();
        res.m_FilePos = _arg1;
        return res;
    }
    public PdfDictionary() {
        super();
    }
}
