CosUtils.java 3.98 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.internal.io.stream.InputByteStream
 */
package com.adobe.internal.pdftoolkit.core.cos;

import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.pdftoolkit.core.cos.CosCloneMgr;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosDocument;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.util.Utility;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.Iterator;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public final class CosUtils {
    private CosUtils() {
    }

    public static CosDictionary cloneOrdinaryKeys(CosDictionary cloned, CosCloneMgr cloneHandler, CosDictionary dict, ASName[] specialKeys) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        Iterator<ASName> keyIterator = dict.keyIterator();
        while (keyIterator.hasNext()) {
            ASName curKey = keyIterator.next();
            if (Utility.nameInArray(curKey, specialKeys)) continue;
            cloned.put(curKey, cloneHandler.clone(dict.get(curKey)));
        }
        return cloned;
    }

    public static CosDictionary cloneOrdinaryKeys(CosDocument toDoc, CosCloneMgr cloneHandler, CosDictionary dict, ASName[] specialKeys) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosDictionary cloned = toDoc.createCosDictionary();
        return CosUtils.cloneOrdinaryKeys(cloned, cloneHandler, dict, specialKeys);
    }

    /*
     * Loose catch block
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     * Lifted jumps to return sites
     */
    static byte[] digestStream(InputByteStream ibs, String digestAlgorithm) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        byte[] byteStream = new byte[8192];
        MessageDigest digester = null;
        try {
            digester = MessageDigest.getInstance(digestAlgorithm);
            while (ibs.bytesAvailable() > 0) {
                int numBytesRead = ibs.read(byteStream);
                digester.update(byteStream, 0, numBytesRead);
            }
            Object var6_7 = null;
            try {
                if (ibs == null) return digester.digest();
                ibs.close();
                return digester.digest();
            }
            catch (IOException e) {
                throw new PDFIOException("Problem occured while closing the input byte stream.", e);
            }
            catch (IOException e) {
                throw new PDFIOException(e);
            }
            catch (NoSuchAlgorithmException e2) {
                throw new PDFSecurityException(e2);
            }
        }
        catch (Throwable throwable) {
            Object var6_8 = null;
            try {}
            catch (IOException e) {
                throw new PDFIOException("Problem occured while closing the input byte stream.", e);
            }
            if (ibs == null) throw throwable;
            ibs.close();
            throw throwable;
        }
    }

    public static <T extends CosObject> int indexOfCosObjectRef(Collection<T> objectList, T obj) {
        int index = 0;
        Iterator<T> itr = objectList.iterator();
        while (itr.hasNext()) {
            if (obj == itr.next()) {
                return index;
            }
            ++index;
        }
        return -1;
    }
}