• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Signed Applet - Problem reading large local files

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am using a signed applet (self-signed) to read files from a clients machine (local file system). Following is the code for buffered reading (the meat):

String thisLine, ret = "";
try{
BufferedReader myInput = new BufferedReader(new FileReader(fn));
while ((thisLine = myInput.readLine()) != null) {
ret += thisLine + "\n";
}
myInput.close();
}
catch (Exception e) {
ret = "Cannot load, exception!";
}

When I read a file <= 512KB, it runs fine/as expected. Now, when I read a file, say for example 1024KB in size, I expect the application to take twice as much time (than 512KB file) and read the file, but instead the applet/browser hangs. As a matter of fact I am not able to read files > 512KB.

So, is there a limit on file size (from local file system) when reading from an applet, or is it to do with the way I am reading it?

Any help, suggestions or comments would be highly appreciated.

Thanks in advance.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

i don't really know but I suggest, that the size of your BufferedReader is too small. Look up the API for the Constructor where you can set the size.

hope this helps

Constanze
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Setting the size of the BufferedReader will only change the size of the buffer, not the amount of data it can read. Setting this too large will cause performance problems. The default (8k) is good enough unless you want to do extensive memory profiling and testing.
You should print the exception and its stack trace to the console. If something bad happens and it breaks something else in your code, you'd never know it. It's also a good idea to sprinkle System.out.println()'s throughout your code when debugging. Gives you an idea as to what's happening in the code. I like to put System.out.print(".") statements in my file read loops to act as a progress indicator.
Rather than concatenating String objects with +=, use a StringBuffer. That will save you numerous object creations, each of which cost processor time and system memory.
Move your close() to a finally block following your catch. If an exception were thrown, your file would never be closed. I've seen enterprise applications killed by similar code leaving database connections open. Take a look at the Java Tutorial: Handling Exceptions for more info.
Applets operate within a limited memory space. This is to prevent malicious applets from growing so large they kill a system. You can control the size of this memory space. For the 1.5 VM, Open the Java Control Panel, click on the Java tab and click on the "view" button in Java Applet Runtime Settings. The settings are described in the Java Tool Documentation.
reply
    Bookmark Topic Watch Topic
  • New Topic