holgerschlegel wrote:Does doc4j loads all parts on load of the package or does it load the parts on demand?
docx4j loads all parts of the package; see LoadFromZipFile and LoadFromZipFileNG.
For starters, you'll be better off with the old LoadFromZipFile, since that doesn't use an intermediate step of copying all the parts into byte arrays (which it does as part of supporting loading a docx from an input stream).
holgerschlegel wrote:If all parts are loaded into memory with the package, could that be changed do load on demand using a memory sensitive cache for loaded parts?
Yes, with relatively few changes you could set things up so that, for example, the main document part, its rels, and say the styles part and numbering parts were loaded into memory.
There is a class Parts (org.docx4j.openpackaging.parts.Parts) which stores the loaded parts. Depending on exactly what you want to do, you could set it up with a reference to the original zip file, so it could find them on demand (SaveToZipFile will need all the parts).
The other thing you could look at is saving (for example just the changed Main Document Part) back to the original file (or a copy of it). I haven't looked to see whether java's Zip implementation supports this; if it doesn't there are several other implementations out there, one of which might.
cheers .. Jason