de.intarsys.pdf.st.STTools Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jpod Show documentation
Show all versions of jpod Show documentation
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.
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();
}
}
}
}
}