NXP-15106: properly close stream
NXP-15106: remove temporary files earlier if possible
NXP-14905: expose position of document in OrderedFolder