Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory problems with opening Images/Security  RSS feed

 
Joshua Kueck
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im having problems with what I thought would be simple applet . Im trying to slideshow through all .jpg files in a certain directory, no matter how many jpegs there are or there size. My problem is, after I go through say 20 or so of them and the list starts over, I start getting out of memory errors. Im guessing the JVM is keeping up with the images for optimization issues, but how do I keep it from doing so. System.gc() and flush dont seem to help any.
Second problem is with Security. My applet, for the most part, runs fine in the appletviewer. However, if I use HTMLConverter and try to run it in my browser, i get AccessControlException, access denied. Im accessing local files, so this doesnt make much sense to me.
 
Joshua Kueck
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I figured out the problem. It has to do with MediaTracker I was using. It was keeping references to the images. I assumed track.addImage(currentImage,0); kept one image at 0, not a subset of images at 0..
Still dont know about the security problem though.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applets can only use files in the server side. you can let applets read or use files hat are on the client side unless they are signed authinticated applets.
if you ran the applet on the same computer try using getCodeBase() instead of documentBase() and see if it works.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joshua, I had a similar problem with MediaTracker but until now, was unable to figure out what was causing it. I would like to know how you solved the problem with MediaTracker keeping references to to image files.
Thanks if you can help.
 
Joshua Kueck
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I knew it wasn't anything else, as everything else was pretty much being created inside the paint method. I just created the MediaTracker inside the paint method, that way its eligible for gc when the method ends. I don't think there is any way to stop MediaTracker from keeping references, you just have to kill the MediaTracker.. but I could be wrong.
 
Joshua Kueck
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roy(or is it Ben), I tried getCodeBase() but I still get security exceptions. Heres what the Java Console had to say:
java.security.AccessControlException: access denied (java.io.FilePermission images read)
 
Joshua Kueck
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahha.. I figured it out ! Because I have to create a new File object to filter threw the directories and what not, it was naturally trying to create it on the client machine. So I had to write this nasty little piece of code

So now it creates it on the server.. Anyone know a cleaner way to do this?
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im glad you worked it out.
sorry for the misinformation.
 
Joshua Kueck
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a problem.. .. Oh, and I didn't work it out. It works fine in my browser but not on a webpage. I don't think I can do this without servlets.. too bad though.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
true. its the whole applet security thing. but then again like i suggested before if you can manage to sign the applet (make it authinticated) then it will run on most browers.
maybe you should read this link
it provides some information about applet security stuff.
 
Joshua Kueck
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link. I don't think its really a security issue, but I dunno. My problem is, the only way to create a File object that is not on the client machine is to use the getCodeBase() in the constructor. This works fine for creating the file on my local machine because the getCodeBase() returns something like File:C:\\blah blah.. hence the subString above. but a problem arises in that if you use an http address, you cant use list(),.. .. the http address isnt really the same as a directory. If i could get the actual address on the server machine.. I'd be set.. but I don't think you can
[ April 25, 2002: Message edited by: Joshua Kueck ]
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you can do it. i dont think it matters the form of the address (it could be url as well).
use the getCodeBase() to get the URL of the clas file. the use the method getPath() on that URL to get the absolutepath.
then create a File from that path name and activate the list().
here is a small program i wrote to show you:

hope it works.
 
Joshua Kueck
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope .. you had me all excited too ... I tried it, but it turned a directory like this "http://personal.lig.bellsouth.net/lig/l/i/lilgoose/firstpica.html" into"/lig/l/i/lilgoose/". Thanks anyways
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry then.
tried my best.
maybe a bartender can know better?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!