public static void disposeDocument(Document old) {
for (Object o : old.getFields()) {
Fieldable f = (Fieldable) o;
try {
if (f.readerValue() != null) {
f.readerValue().close();
} else if (f instanceof LazyTextExtractorField) {
LazyTextExtractorField field = (LazyTextExtractorField) f;
field.dispose();
}
} catch (IOException ex) {