• Post Reply Bookmark Topic Watch Topic
  • New Topic

notifying the app that a jpeg has been added  RSS feed

 
peter m hayward
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have followed up on the watcher service and finally got it to produce a console output that describe that action that has taken place, e.g. file modified deleted, where this seem to be what i need to be doing in order to get the app to see a recently added jpeg to a given folder , I have no idea as to what i do to the app so it see the new jpeg, currently the only way this is achieved is restarting the app the code below is not my code its for a tutorial which i have change just one thing the directory being watched, but like i said how i use this information to get the app to see the added jpeg is still a bit of a mystery
so can some please explain how restating the app achieves this and the just maybe i can use the results from the watcher service to trigger the same event thus remove the need to restart that app

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would it mean for "the app to see the added jpeg"? What does it do with the image(s)?

I would assume that the app scans the directory at startup for all present images...? If so, it just needs to do a rescan if something changes, and adapt its internal data structure accordingly.
 
peter m hayward
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:What would it mean for "the app to see the added jpeg"? What does it do with the image(s)?

I would assume that the app scans the directory at startup for all present images...? If so, it just needs to do a rescan if something changes, and adapt its internal data structure accordingly.


Hi the images are pictures of books the app reads the bar code and communicates with mysql then displays the result read to upload to the internet, I have searched high and low trying to find what netbeans does and how it track resources in the hope i could rescan as you suggest and I now have a mechanism that will track the changes made to the file containing the jpegs

To expand upon the why this problem occurs some times the jpeg is of a different cover and therefore needs to be replace for the correct one and it may well be that it is added to the folder from a digital camera

if possible could tell hoe to initiate a rescan

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I don't really understand what the images are used for, but again: whatever the app is doing at startup, why can't it do again during runtime if it detects any changes? What, precisely, is it that it does at startup with those images? You have the source code, right?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
peter m hayward wrote:To expand upon the why this problem occurs some times the jpeg is of a different cover and therefore needs to be replace for the correct one and it may well be that it is added to the folder from a digital camera

if possible could tell hoe to initiate a rescan


If you're talking about updating an image when a file is replaced on disk (i.e. existing file name, new contents), then the answer will depend on how you loaded the images from files in the first place. For example, if you are directly or indirectly loading via java.awt.Toolkit then that class caches loaded images so you would force a reload by flush()ing the Image; if you use ImageIO#read(...) then you need to read the file to load the Image afresh.
 
peter m hayward
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your reply it seems as though i maybe going about this the wrong way and creating the problem .
The work flow is to scan the bar code on the book this value is entered into a jtextField from there it is used to create a url to a folder on the C drive
e.g.
9780552136716 being a typical number, now rather than have one huge folder “Apicture” it has sub directories taking the first 7 numbers from the original number thus 9780552 so the picture url becomes /9780552/97805521367161.jpg also there is an addition 1,2,3 up to 6 added to the end of the original isbn number this facilitates displaying up to six of the them at a time and when the correct one is clicked by the user the remaining 5 are hidden and the selected one place in centrally by transferring it to another jlabel just for effect
Now here is the simple of nothing else code i have adopted to get the image from the folder and place on the jlabel , here again this being a legacy idea and i may well be that there is now an improved method of displaying pictures in java, as i am now using version 7 with netbeans 7.2 IDE

Recapping on what normally happens a given bar code is scanned if jpeg is within the folder everything is fine should it not be there this code shows a blank book picture

At which point a suitable jpeg is sourced and placed in the correct folder but the app does not see it until it has been restarted where upon it does and again everything is fine.
So am i to take it that netbeans somehow logs all the jpegs on my computer? In order that it sees them?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds odd. The results of a File.exists() check aren't cached, so any time you perform one it should report whether the file exists at that particular time. And if the file is subsequently added (or removed), the results should be different the next time around.

I'm a bit confused by your repeated mention of NetBeans - that is an IDE, which would not be present at runtime. It sounds as if you run the code through it, which might alter the runtime behavior in subtle ways. Have you tried running the code outside of NetBeans?
 
peter m hayward
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:That sounds odd. The results of a File.exists() check aren't cached, so any time you perform one it should report whether the file exists at that particular time. And if the file is subsequently added (or removed), the results should be different the next time around.

I'm a bit confused by your repeated mention of NetBeans - that is an IDE, which would not be present at runtime. It sounds as if you run the code through it, which might alter the runtime behavior in subtle ways. Have you tried running the code outside of NetBeans?


It my fault your are spot on i have not tried to run it out side the ide as i am using the app my self just to test it and when i find an issue i go in and fix it but if i create a jar then i would need to go in fix it and then create a new jar and would i be able to over write the original jar as this aspect of java is something i have not done yet

the File.exists() bit works fine sorry for giving the wrong impression its the fact that an added jpeg to any given fold will not show up till that app is restarted
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the File.exists() bit works... its the fact that an added jpeg to any given fold will not show up till that app is restarted

Now I'm confused. If File.exists() works fine -which I take to mean that it returns that correct result even for files that were created after the app was started- then what does "added jpeg to any given fold will not show" mean, exactly?
 
peter m hayward
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
the File.exists() bit works... its the fact that an added jpeg to any given fold will not show up till that app is restarted

Now I'm confused. If File.exists() works fine -which I take to mean that it returns that correct result even for files that were created after the app was started- then what does "added jpeg to any given fold will not show" mean, exactly?


Thanks for your reply, part of the problem is that the data base (mysql) is just data pertaining to given isbns and has no bearing as to if the is a jpeg or not, in most case one exist but the are the occasion when it is not in the corect folder or absent all together thus the need to add one to the correct folder and it is at this point i am stuck because the app does not see that newly added one till i restart the app, the File.exists() is used in two way one to prevent app continually searching for a none existent jpeg and two to provide notification to the user by displaying a blank book

how do i trigger a re-scan so it would see the recently added jpeg?

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems we're always coming back to the same question: What does "because the app does not see that newly added one" mean if not that a File.exists() check returns the correct result?

how do i trigger a re-scan so it would see the recently added jpeg?

Does this mean that some kind of scan (of the file system?) is done at application startup time? If so, and the results are cached, then the cache needs to updated (or the scan redone) if something changes in the file system. (That's what I asked in my first and second posts.)
 
peter m hayward
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:It seems we're always coming back to the same question: What does "because the app does not see that newly added one" mean if not that a File.exists() check returns the correct result?

how do i trigger a re-scan so it would see the recently added jpeg?

Does this mean that some kind of scan (of the file system?) is done at application startup time? If so, and the results are cached, then the cache needs to updated (or the scan redone) if something changes in the file system. (That's what I asked in my first and second posts.)


Thank you for bearing with me, i guess i mean the caching process as clearly the jpeg in question has not been cached as it did not exist at the time and is therefore absent and once added restating the application re-runs the cashing process thereby including it so it is this mechanism i am seek to re-run with out restarting the whole app

what i think i need to do would be in the first instance have a button that triggers the re-cache process, so i can go and add the jpeg to the folder click the button and everything would be as if i had restarted the app, then after this works i would want to remove the button and get the watcher service to do it instead

hope this is clear
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!