Handling large documents
I am starting this topic to see if anyone else is interested in the issues involved with handling large (or enormous) documents using Swing.
I have been experimenting with viewing large documents with a JTextArea. The default PlainDocument (and GapContent) are OK for documents upto about 1MB (possibly larger if the GapContent was created with an appropriate initial size). There is a bug in the top 25 list which relates to the problems involved with larger documents:
Some of the issues in that bug do appear to have been addressed. However for large (and enormous) files, problems still remain especially with the way that lines are managed.
I have written a Document class which allows me to view
files of 15MB (over 300000 lines) using the standard
JTextArea without any memory problems. With a little more
work (loading the document in the background) I hope to be
able to handle the 100MB+ trace files I sometimes create.
My experimental classes have the following properties
1) The document is read only
2) The file is memory mapped using the nio classes
3) I parse the file quickly to locate lines, but only store their
position in an int (no object created per line). Line
elements are only created on request
4) The mapped byte buffer is decoded into characters on
demand (and the decoded blocks cached). This only works
with some character encodings.
If anyone is interested I can add more details.