Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Has StyledText a maximum input for data?
icon5.gif  Has StyledText a maximum input for data? [message #511599] Tue, 02 February 2010 08:50 Go to next message
Bjoern Berg is currently offline Bjoern Berg
Messages: 41
Registered: November 2009
Location: Essen
Member
I am trying to read in files with a size about 10 to 60 MB and display their content in a StyledText widget.

First it was also a problem to display the 10 MB files in the StyledText, but after changing the NIO-Routine to a loop reading smaller pieces it was no problem to read in the whole file.

But with files about 60 MB I still have the problem. So my question is, is there a capacity limit for StyledText or do I something wrong in the read-in routine?

The code for the read-in-routine looks like this:

[...]
StyledText transcript = new StyledText(top, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
[...]
if (file != null && file.exists()) {		
  FileInputStream istream = new FileInputStream(file);
  if (istream == null) return;
  
  FileChannel fc = istream.getChannel();
  // Get the file's size and then map it into memory
  int sz = (int)fc.size();
  int cs = 0;
  final int piece = 5120 * 1024;		// read almost about 5 MB into cache
  while (cs < sz) {
     MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, cs, 
		(sz - cs) < piece ? (sz - cs) : piece);

     // Decode the file into a char buffer
    CharBuffer cb = decoder.decode(bb);							
   transcript.append(new String(cb.array()));
   transcript.redraw();							
   cs += piece;
  }
 fc.close();
 istream.close();
Re: Has StyledText a maximum input for data? [message #511704 is a reply to message #511599] Tue, 02 February 2010 15:29 Go to previous messageGo to next message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
Registered: July 2009
Senior Member
Hi,

StyledText does not specify a content size limit, but 60MB is larger than is
typically envisioned for uses of StyledText, so it's possible that you're
seeing a bug (eg.- perhaps some int field within StyledText is hitting its
limit, etc.).

That being said, feeding a StyledText 60MB of content up-front is not a good
approach to use. This content should be provided on an as-needed basis
since the user will likely view < 1% of it. This is described in
http://www.eclipse.org/articles/StyledText%202/article2.html .

It would also be interesting to get an idea of how much text can be set
up-front (you said that 10MB of text worked, does 20MB? etc.)

Grant


"Bjoern Berg" <rollin.hand@gmx.de> wrote in message
news:hk8p0p$l0n$1@build.eclipse.org...
> I am trying to read in files with a size about 10 to 60 MB and display
their content in a StyledText widget.
>
> First it was also a problem to display the 10 MB files in the StyledText,
but after changing the NIO-Routine to a loop reading smaller pieces it was
no problem to read in the whole file.
>
> But with files about 60 MB I still have the problem. So my question is, is
there a capacity limit for StyledText or do I something wrong in the read-in
routine?
>
> The code for the read-in-routine looks like this:
>
>
> [...]
> StyledText transcript = new StyledText(top, SWT.BORDER | SWT.MULTI |
SWT.H_SCROLL | SWT.V_SCROLL);
> [...]
> if (file != null && file.exists()) {
> FileInputStream istream = new FileInputStream(file);
> if (istream == null) return;
>
> FileChannel fc = istream.getChannel();
> // Get the file's size and then map it into memory
> int sz = (int)fc.size();
> int cs = 0;
> final int piece = 5120 * 1024; // read almost about 5 MB into cache
> while (cs < sz) {
> MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, cs,
> (sz - cs) < piece ? (sz - cs) : piece);
>
> // Decode the file into a char buffer
> CharBuffer cb = decoder.decode(bb);
> transcript.append(new String(cb.array()));
> transcript.redraw();
> cs += piece;
> }
> fc.close();
> istream.close();
>
Re: Has StyledText a maximum input for data? [message #512942 is a reply to message #511704] Mon, 08 February 2010 12:06 Go to previous message
Bjoern Berg is currently offline Bjoern Berg
Messages: 41
Registered: November 2009
Location: Essen
Member
Grant Gayed wrote on Tue, 02 February 2010 10:29

It would also be interesting to get an idea of how much text can be set
up-front (you said that 10MB of text worked, does 20MB? etc.)



Hi,

sorry for the late response and thank you for the link. This is a very interesting article and I think the way described there will fix the problem.

I can tell you that up to 40 MB can be read into a StyledText without problems - more crashes the VM, also if you increase memory for the VM.

- Bjoern
Previous Topic:Button selection event
Next Topic:How to scroll down the vertical bar?
Goto Forum:
  


Current Time: Thu Oct 02 10:46:35 GMT 2014

Powered by FUDForum. Page generated in 0.01571 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software