All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.intarsys.pdf.st.STTools Maven / Gradle / Ivy

Go to download

This is a fork of http://sourceforge.net/projects/jpodlib/ as development seems to be frozen. We're providing some bug fixes along with deployments to maven.

There is a newer version: 2.0
Show newest version
package de.intarsys.pdf.st;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class STTools {

    private STTools() {
    }

    public static class EntryCollector implements IXRefEntryVisitor {

        private List entries = new ArrayList();

        public List getEntries() {
            return entries;
        }

        @Override
        public void visitFromCompressed(STXRefEntryCompressed entry) throws XRefEntryVisitorException {
        }

        @Override
        public void visitFromFree(STXRefEntryFree entry) throws XRefEntryVisitorException {
        }

        @Override
        public void visitFromOccupied(STXRefEntryOccupied entry) throws XRefEntryVisitorException {
            if (entry.getObjectNumber() == 0) {
                return;
            }
            entries.add(entry);
        }
    }

    public static List getOccupiedEntries(STXRefSection section) throws IOException {
        EntryCollector collector = new EntryCollector();
        visitEntries(section, collector);
        return collector.getEntries();
    }

    public static void visitEntries(STXRefSection section, IXRefEntryVisitor visitor) throws IOException {
        Iterator i = section.subsectionIterator();
        while (i.hasNext()) {
            STXRefSubsection subsection = (STXRefSubsection) i.next();
            for (Iterator ie = subsection.getEntries().iterator(); ie.hasNext(); ) {
                try {
                    ((STXRefEntry) ie.next()).accept(visitor);
                } catch (XRefEntryVisitorException e) {
                    // in this context the exception type is always an
                    // IOException
                    throw (IOException) e.getCause();
                }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy