How to display a text file

What is the best way to display a text file with huge size. I have tried Panel.add label and text fields. But this fails with OutOfMemory issue.

I use Vaadin 6.4.3.

Any help ?.

My requirement is to display contents of a text file as non-editable.

Thanks

Seems like you need to increase the memory available to your JVM – using -mx java command param most likely.

How big is the text file? It is possible you’ll need to display the text file in chunks so as not to need all in memory at once, or perhaps you’ll need to display it in a popup browser window with an old fashioned JSP/servlet streaming the contents back.

I am OK to display in Chunks. What is the better approach / option ?

Hi,

What is “huge” in your case?

I think the most scalable solution would be using a Table to display the file with each text row as a table row. This would require a special container that gives access to the file rows through the Container interface. If the file is “huge”, you wouldn’t even need to load it all into memory - you’d just need to build an index of the line positions (or, say, every tenth line) in the file and use random access to read the chunks.

Well, there’s of course the ~half-million line limit in Table.

I have around 600000 lines in the text file. I was trying add each line as a label into a Panel , which was throwing “OutOfMemory” exception. My issue is not reading the text file. I am looking for what is the best way to display the content of the file. I can try the table solution. Is there any other way to display it ?

Thanks

You definitely don’t want to create 600,000 Labels and put those in a Panel, the overhead of the components would be huge. You could have just one Label with somewhat large file content, perhaps 10,000 lines or so, perhaps using the CONTENT_PREFORMATTED content mode. But browsers would probably fail with 600,000 lines of text and it would be in any case silly to load that much data to the browser - a lazy solution is better.

Besides using 1) Label inside Panel + paging, 2) using Table, I don’t know if there area any other easy solutions using the core components at least.

The Table’s row limit is somewhere between 500,000 and 1,000,000 rows, depending on the browser and the font. I’ve seen a report that 800,000 works still ok in some browser. It’s actually a pixel limit - the scroll area is a HTML layer that high (about 500000 x 20 = 20 million pixels). So, using a smaller font gives you more rows.

If you use the Table approach, you could use the LazyContainer from the ArrayContainer add-on if you want to avoid implementing a Container from scratch.

Thanks. that helped me a lot.

Hello,
I was wondering what code to use
to display a text file
Thanks