FileListener not catching file change

I did a few searches to try and find a File listener that would listen for changes made to a file such as contents or extensions changes. I cam upon the following interface and class:
package customdisc;
import java.io.File;
public interface FileListener
    void fileChanged(File file);
package customdisc;
import java.util.*;
import java.io.File;
import java.lang.ref.WeakReference;
* Class for monitoring changes in disk files.
* Usage:
* 1. Implement the FileListener interface.
* 2. Create a FileMonitor instance.
* 3. Add the file(s)/directory(ies) to listen for.
* fileChanged() will be called when a monitored file is created,
* deleted or its modified time changes.
public class FileMonitor
    private Timer timer_;
    private HashMap files_; // File -> Long
    private Collection listeners_; // of WeakReference(FileListener)
    public FileMonitor(long pollingInterval)
        files_ = new HashMap();
        listeners_ = new ArrayList();
        timer_ = new Timer(true);
        timer_.schedule(new FileMonitorNotifier(), 0, pollingInterval);
    public void stop()
        timer_.cancel();
    public void addFile(File file)
        if (!files_.containsKey(file))
            long modifiedTime = file.exists() ? file.lastModified() : -1;
            files_.put(file, new Long(modifiedTime));
    public void removeFile(File file)
        files_.remove(file);
    public void addListener(FileListener fileListener)
// Don't add if its already there
        for (Iterator i = listeners_.iterator(); i.hasNext();)
            WeakReference reference = (WeakReference) i.next();
            FileListener listener = (FileListener) reference.get();
            if (listener == fileListener)
                return;
// Use WeakReference to avoid memory leak if this becomes the
// sole reference to the object.
        listeners_.add(new WeakReference(fileListener));
    public void removeListener(FileListener fileListener)
        for (Iterator i = listeners_.iterator(); i.hasNext();)
            WeakReference reference = (WeakReference) i.next();
            FileListener listener = (FileListener) reference.get();
            if (listener == fileListener)
                i.remove();
                break;
    private class FileMonitorNotifier extends TimerTask
        public void run()
// Loop over the registered files and see which have changed.
// Use a copy of the list in case listener wants to alter the
// list within its fileChanged method.
            Collection files = new ArrayList(files_.keySet());
            System.out.println("There are " + files.size() + " files");
            for (Iterator i = files.iterator(); i.hasNext();)
                File file = (File) i.next();
                long lastModifiedTime = ((Long) files_.get(file)).longValue();
                long newModifiedTime = file.exists() ? file.lastModified() : -1;
// Chek if file has changed
                if (newModifiedTime != lastModifiedTime)
// Register new modified time
                    files_.put(file, new Long(newModifiedTime));
// Notify listeners
                    for (Iterator j = listeners_.iterator(); j.hasNext();)
                        WeakReference reference = (WeakReference) j.next();
                        FileListener listener = (FileListener) reference.get();
// Remove from list if the back-end object has been GC'd
                        if (listener == null)
                            j.remove();
                        else
                            listener.fileChanged(file);
}Now, in my listening class I have instantiated FileMonitor and I am implementing FileListener.
Here are the few parts of my listening class:
public class CreateDisc implements FileListener
    private static File isoImage;
    private static File discLabel;
    private static DVDOrder dvdOrder;
    private static Order order;
    private static File job;
    private static FileMonitor fileMonitor = new FileMonitor (1000);
    public CreateDisc(File iso, File img, Order order)
        try
            fileMonitor.addListener (this);
            CreateDisc.isoImage = iso;
private static void buildJob()
        Writer output = null;
        try
            String isoPath = CreateDisc.isoImage.getAbsolutePath();
            String labelPath = CreateDisc.discLabel.getAbsolutePath();
            int priority = CreateDisc.order.getDiscPriority();
            String jobPath = Config.BURNER_JOB_PATH + CreateDisc.order.getCustName() + "_" + CreateDisc.order.getWebID() + ".meow";
            job = new File(jobPath);
            System.out.println("Adding \"job\" to the monitor...");
            fileMonitor.addFile(job);
            output = new BufferedWriter(new FileWriter(job));
            // Create a JobID
            output.write("JobID=" + CreateDisc.order.getCustName() + "_" + CreateDisc.order.getWebID() + "\n");
            // Create a ClientID
            output.write("ClientID=" + CreateDisc.order.getCustName() + "_" + CreateDisc.order.getWebID() + "\n");
            // Set a priority if we need one; otherwise, the application defaults to 4
            if (priority < 4)
                output.write("Importance=" + priority + "\n");
            // Set the ISO path
            output.write("ImageFile=" + isoPath + "\n");
            // Set the data type if it's a DVD
            if (CreateDisc.order.getDiscType().equals("DVD"))
                output.write("DataImageType=UDF\n");
            // Close the disc
            output.write("CloseDisc=YES\n");
            // The disc label path
            output.write("PrintLabel=" + labelPath + "\n");
            // Give the disc a name
            output.write("VolumeName=" + CreateDisc.order.getDiscName() + "\n");
            // Reject the disc if it isn't blank
            output.write("RejectIfNotBlank=YES\n");
            // Notify the client on errors
            output.write("NotifyClient=YES");
            // Set the drive ID
            //output.write("DriveID=");
            // Set the bin to pull the discs from
            //output.write("BinID=");
        catch (IOException ex)
            Logger.getLogger(CreateDisc.class.getName()).log(Level.SEVERE, null, ex);
        } finally
            try
                output.close();
            catch (IOException ex)
                Logger.getLogger(CreateDisc.class.getName()).log(Level.SEVERE, null, ex);
    public void fileChanged(File file)
        System.out.println("File " + file.getName() + " has changed.");
    }So, I instantiate the FileMonitor, add my CreateDisc class as the listening object, and then I add a File object to the listener. I know the file is getting added because my output is as follows:
There are 0 files
There are 0 files
There are 0 files
params =  -quiet -o C:\ISO\224561\224561.iso -dvd-video C:\DOCUME~1\tlee\LOCALS~1\Temp\KaraokeDVDBurner\dvd
There are 0 files
Adding "job" to the monitor...
There are 1 files
There are 1 filesWhenever I modify the file at all, whether it be the file contents or removing the file completely, my abstract method fileChanged() is never called. So after knowing that my file is added to the FileMonitor object, I'm lost as to why it isn't noticing changes. Any thoughts?

Well I figured it out. Turns out I was referencing the class instead of instantiating it. fileMonitor.addListener (this); was in the constructor, but the constructor was never called.
So, this works.
// Check to see if we are currently making an ISO
                if(!Config.IS_MAKING_ISO && !newOrderModel.isEmpty())
                    Config.IS_MAKING_ISO = true;
                    new Thread()
                        @Override
                        public void run()
                            // CreateDisc.makeDisc((Order) CustomUI.newOrderModel.get(0)); class reference
                            CreateDisc createDisc = new CreateDisc();
                            createDisc.makeDisc((Order) CustomUI.newOrderModel.get(0));
                    }.start();
                }Now onto the WeakReference. I don't finalize the CreateDisc object, but once all file activity has completed and the File references are gone, the system will finalize it, correct? And then it will be GCed.

Similar Messages

  • NWDS does not allow file change.

    Hello friends,
    I am developing an Netweaver ISA eCommerce application. I got a problem to change one file of this application. I have opened my NWDS and I changed some files (the activity was created to put the changes) but one of the files that I must change does not accept the modification. I mean, I can not edit that file. If I remove the write protection, the NWDS allows the change, but this way is not correct because the file changed does not go to the activity.
    I have already seen this problem before and I solved it through an "edit" command on DTR perspective (right button over the file). But this option is not available at this time.
    Can anyone help me?
    Thanks!
    Rodrigo.

    I have found a good way to solve the problem. I removed the DC from client and I created it again. After that, NWDS allowed the file editing.
    I do not know why it happened but it seems to be a bug on Developer Studio.
    Regards,
    Rodrigo.

  • Video layers in CS6 - not reflecting file changes

    we do 3D rendering, breaking images into 3D render passes that we render to a directory, then load those passes up as video layers to put them back together in Photoshop.  Everyday we make 3D adjustments, render every night (to files of same name in same location), and in the morning pull up the PSD- where all the passes SHOULD have updated.
    This workflow all worked fine with CS5.5 extended, but in CS6, the video layers don't seem to be automatically updating, and we're getting the prior day's definitition, while there are no indications that the file isn't found.
    This problem is on Windows7 machines, and we've disabled the windows search service thinking the defnitions were still in the cache - to no avail.
    Any help is appreciated- Jon

    My jsp code
    <%@page language="java"
         import="java.sql.*,java.io.*,mySAP.*,java.net.URL;"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <%!StringBuffer stringbuffer = new StringBuffer();
         int testemp;%>
    <%
         String dofrom;
         String doto;
         String s;
         String s1;
         dofrom = request.getParameter("DOFrom");
         doto = request.getParameter("DOTo");
         ResultSet resultset;
         String flag = request.getParameter("dall");
         mySAP.JcoTest2 obj = new mySAP.JcoTest2();
         //StringBuffer sb = obj.fetchData("one", "two");
         String sb = obj.checking();
         out.println(sb);
         try {
              StringBuffer stringbuffer = new StringBuffer();
              String separator = System.getProperty("file.separator");
              String path = System.getProperty("user.dir") + separator;
         } catch (Exception e) {
              out.println("error%%%%%%%%%" + e);
    %>
    </body>
    </html>here i am calling JcoTest2 from mySAP pack...
    first time it is showing correct output of JcoTest2 .if i change JcoTest2 and copy and run .jsp is outputing the old program value.
    .I used to complie my program in local machine and copy the class file and jsp file into the server(linux).
    Regards

  • DWMX not saving file changes

    This is weird.
    I am changing the onMouseOver to all lower case so it
    vaildates with a xhtml
    doctype.
    So I make the change, save the file, even close DW.
    But when I open it up again, the onmouseover is now back to
    onMouseOver.
    I was able to change all other instances of onMouseOver via a
    sitewide ctrl
    find and replace and it even shows as if it's replaced this
    one file's
    instances, but every time I open this file, it's back to the
    mixed case
    rather than lower case.
    It's a similar situation with another file that just will not
    accept
    onsubmit and keeps reverting back to onSubmit. It's a
    conspiracy! :)
    Anyone have any suggestions?
    Cheers,
    Lossed
    __when the only tool you have is a hammer, everything looks
    like a nail __

    Glad you solved it. Get that nut fixed, will you? 8)
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Lossed" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks for getting back to me Murray,
    >
    > It was the nut behind the wheel that was faulty.
    >
    > In the code format preferences, I have the default case
    for tags and
    > attributes set to lowercase, and I have it set to
    override the case of
    > tags and attributes.
    > This I assumed would set all tags and attributes to
    lowercase irrespective
    > of what the tag library settings were. I mean, that is
    what I consider
    > 'override' to mean - it overrides the users typeing or
    more specific tag
    > library settings.
    >
    > But it doesn't privide that kind of global setting, it
    seems.
    >
    > After individually setting the attributes of each of the
    tags in the tag
    > library, it does keep the code lowercase as I had
    originally intended.
    >
    > thank goodness for that. I can ill-afford to lose
    anymore hair :)
    >
    >
    >
    >
    >
    >
    >
    > "Murray *ACE*" <[email protected]>
    wrote in message
    > news:[email protected]...
    >> What do your preferences specify about rewriting
    code?
    >>
    >> --
    >> Murray --- ICQ 71997575
    >> Adobe Community Expert
    >> (If you *MUST* email me, don't LAUGH when you do
    so!)
    >> ==================
    >>
    http://www.dreamweavermx-templates.com
    - Template Triage!
    >>
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    >>
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    >>
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    >> ==================
    >>
    >>
    >> "Lossed" <[email protected]> wrote in
    message
    >> news:[email protected]...
    >>>
    >>> This is weird.
    >>> I am changing the onMouseOver to all lower case
    so it vaildates with a
    >>> xhtml doctype.
    >>> So I make the change, save the file, even close
    DW.
    >>> But when I open it up again, the onmouseover is
    now back to onMouseOver.
    >>>
    >>> I was able to change all other instances of
    onMouseOver via a sitewide
    >>> ctrl find and replace and it even shows as if
    it's replaced this one
    >>> file's instances, but every time I open this
    file, it's back to the
    >>> mixed
    >>> case rather than lower case.
    >>>
    >>> It's a similar situation with another file that
    just will not accept
    >>> onsubmit and keeps reverting back to onSubmit.
    It's a conspiracy! :)
    >>>
    >>> Anyone have any suggestions?
    >>>
    >>> --
    >>> Cheers,
    >>> Lossed
    >>> __when the only tool you have is a hammer,
    everything looks like a nail
    >>> __
    >>>
    >>
    >>
    >
    >
    >

  • My MacBook Pro keeps making copies of a document that I am trying to save. I don't want to duplicate the file. I only want to save it on both my hard drive and my external hard drive. I do not want to change its name for every save, which the computer see

    My MacBook Pro keeps making copies of a document that I am trying to save. I don't want to duplicate the file. I only want to save it on both my hard drive and my external hard drive. I do not want to change its name for every save, which the computer seems insistent on doing. Help!!

    11lizzyp wrote:
    can't be saved because the file is read-only.
    I did not create the file to be read-only. I created to be able to continue to add to it as I work on it.
    More on versions here:
    http://support.apple.com/kb/ht4753
    local snapshots:
    http://support.apple.com/kb/HT4878
    Sounds like a permissions problem ie read only.
    If running repair permissions from your DiskUtility.app does not sort it,
    Someone should jump in here with erudite and concise fix.

  • Not able to save file changes on HCP Web IDE

    Hi
    i am not able to save the file changes on my HANA XS Application created on HCP Trail Account using Wed IDE. This problem does not occur always but now it has become frequent. On click of save button waiting icon comes up and then after minutes it shows error message as Error while Saving.
    I normally use HCP Web IDE platform for all development work.
    My Account ID : i314165trial
    Can anybuddy tell me what is the issue as this is will hamper the development process.

    Check the permissons on the folder and drive, not just on the file.

  • I have a pdf file, how do it ONLY View but not can get changed, I mean locked

    I have a pdf file, how do it ONLY View but not can get changed, I mean locked?

    Use the Security tab in the properties of the document.

  • Latest Lithroom 5.6 does not recognize my .cr2 raw file format and Windows 7 it asociates with my older raw plug in in Ps CS5.5. I am not able to change default program for .cr2 in the properties pannel...

    Latest Lithroom 5.6 does not recognize my .cr2 raw file format and Windows 7 it asociates with my older raw plug in in Ps CS5.5. I am not able to change default program for .cr2 in the properties pannel...
    every new released update of Lr from v 5.2 changed somethin in my Windows 7 Professional settings. I am stucked. Can somebody help me please? Many thanks. Andrej

    Hi Jim,
    yes after I imported my .cr2 raw files into new catalog it started to work. Windows 7 still does not recognize them but I can edit them as you said within the Lr5.6 and then export them into .psd or .dng files...as needed.
    I bought Lr5 only because I got present - my new camera Cannon 70D and because my older Photoshop CS5.5 raw plugin does not recognize. cr2 files.
    Many thanks for your help.
    Andrej.

  • I have nine, 1-page PDF files that are accessible and need to combine into 1 PDF file.  I have tried appending, adding and the combine PDFs process. The file created is not keeping my changes. The created file is partially accessible but I have to re-fix

    I have nine, 1-page PDF files that are accessible and need to combine into 1 PDF file.  I have tried appending, adding and the combine PDFs process. The file created is not keeping my changes. The created file is partially accessible but I have to re-fix issues I had fixed in the single files. I need suggestions on what else can be done if any. Using Acrobat pro XI.

    Out of habit, I tend to combine PDF files in the Page Thumbnails pane by right-click then "Insert Pages" -> "From File". For me, this preserves the tags from both documents, although the tags may have to be moved into the right location (if I recall correctly the tags for the inserted pages get put at the end of the tag structure, regardless of where the pages are inserted), If I first put the tags for the document to be inserted inside a container tag like Section, it makes the process easier. Moving that set of tags to the right place is the only re-fixing that I recall having to do. What behavior are you experiencing?
    a 'C' student

  • Just tried to import CD in my iTunes music library, but get this error code "error occurred while converting file. You do not have the privilege to make changes"....any thoughts? Have not tried to change anything- only import CD ??

    Just tried to import a new CD into my iTunes music library, but get this error code "error occurred while converting file. You do not have the privilege to make changes"....any thoughts? Have not tried to change anything- only import CD ??

    Do you have read& write permissions to your iTunes library?
    See this thread: Re: "Error has occurred... You do not have the privilege to make changes."

  • Excel file changes on PC not reflected on BT Cloud...

    This is a strange one....if I make a change to an Excel file on my laptop...it is backed up to BT Cloud ok....but if I access the file from my mobile phone...it still shows the original file without the change....BT Helpdesk stated that BT Cloud does not support Excel file changes...is this correct?...I find that astounding!

    I need to add that Word document and notepad files do not suffer from the same problem....changes are reflected ok when access from mobile device or my laptop on the cloud.

  • When I tried to run php file I am getting the following error message, "/home/karthick/Desktop/PHP files/third.php could not be opened, because the associated helper application does not exist. Change the association in your preferences." How to fix this?

    When I tried to run php file I am getting the following error message, "/home/karthick/Desktop/PHP files/third.php could not be opened, because the associated helper application does not exist. Change the association in your preferences." How to fix this?

    first, you just asked me to use MS file Explorer to see what the properties were.,..and to ask what happened. Yes - that's on my hard drive. The problem I have is opening word files in a DB that is web enabled.....I've used Firefox browser for that, and everything else , for years...... When I look at the Tools, and options on FireFox., as your support page noted.....NOTHING is listed in the Applications tab....hence my note asking for help. The file I need to open is a Word file out on a web enabled DB. It's not on my hard drive - I have to problems opening docs there - but for that, I don't use Firefox

  • My JSP file does not reflec the change of a Bean

    My test environment: Win 2000, JDK 1.3.1, OC4J(standalone)
    My problem:
    In servlet, the change of a Strng value is reflected at the next refresh of a browser.
    But, when a jsp file call a bean's getXXX(return a String value) method, and if the String value of that bean is changed, the next refresh or visit to that jsp file does not reflect the change of that bean.
    For example:
    1) TestClass.java
    public class TestClass {
    private String txt;
    public class TestClass {
    txt = "Test"; ----- (g
    public String getTxt() {
    return txt;
    2) test.jsp
    <html><body>
    <h2>
    <% TestClass test = new TestClass(); --(h
    out.print(test.getTxt()); %> --(i
    </h2>
    </body></html>
    In my first vistit to "http://localhost:8888/test.jsp" the brower shows "Test" String, but after I change the txt value to "Test1"((g) the brower does not reflect the change.
    I found that if I use <jsp:useBean id="test" class="TestClass" /> instead of (h-(i line, the brower reflects the change of the bean.
    Why does this occur?
    Thaks in advance.
    PS) In some cases(Not above example), I get the java.lang.ClassCastException.
    So Each time I change a Servlet or a Bean, I restart OC4J.
    null

    SangKyu,
    <jsp:useBean > has a property called scope, which defaults to "page".
    So the bean gets reset everytime you reload the page.
    Can I suggest that you set it to "session"?
    The following syntax card I have found userful:
    http://java.sun.com/products/jsp/syntax.pdf
    Cheers,
    Scott
    Atlassian - Supporting YOUR 'Orion/OC4J' World
    http://www.atlassian.com - [EMAIL][email protected][EMAIL]

  • Forcing a "deep search" Time Machine backup (to catch all changes)

    Time Machine normally depends upon the new, Leopard, file system event logs to know what to include in an incremental backup. But if there is a problem with a backup due to file system corruption or whatever, Time Machine may miss some files AND NOT CATCH THEM LATER when the subsequent backups happen, apparently because they are no longer marked as having been changed since the last backup.
    If you have removed a corrupted file/directory or otherwise want to make sure Time Machine really does catch everything, you could of course erase the Time Machine disk and have it start over.
    OR you could force a "deep search" backup. A deep search backup happens whenever Time Machine decides the file system event log can not be trusted. In that case Time Machine digs through the entire source file system to decide what to include in the next incremental backup. You will know this is happening because the "preparing" phase takes a long time (perhaps 20 minutes or so) even though the amount of data eventually backed up is not that big. The time of the preparing phase will probably be comparable to the time to do a Repair Permissions pass in Disk Utility. There is also a message added to the Console by the "backupd" process indicating it is also going "deep".
    Well it turns out that one of the easiest ways to make Time Machine decide not to trust the file system event log is to boot from the Leopard install DVD. Apparently the event log is marked as non-trustable since a source external to the file system (the software running from the install DVD) may have altered it.
    So boot from the install DVD and then immediately Restart from your main hard drive. The next incremental backup Time Machine does will be a "deep search" backup.
    --Bob

    BobP1776 wrote:
    Well it turns out that one of the easiest ways to make Time Machine decide not to trust the file system event log is to boot from the Leopard install DVD. Apparently the event log is marked as non-trustable since a source external to the file system (the software running from the install DVD) may have altered it.
    Thanks, this was very useful information to me this evening! I was puzzled that the TM backup of my daughter's MacBook was missing several changed files. I tried your "DVD trick", and it solved the problems!
    Now the question is why Time Machine didn't understand that it should have done a deep traversal? It seems it has logged its own bug: The log says: "Avoided deep traversal due to exclusion list change". Indeed, I did change the exclusion list, as I wanted to add a portable external drive. I guess I should report this bug to Apple...

  • After o download the browser ,i get message that says can not open file what do i need to do to download the browser i have tried 5 times get same message

    its the same shit i asked before after i download the browser i get message can not open file what do i do to dwonload the browser

    That message is usually a sign that you tried to roll back to an earlier build of iTunes, but occasionally I've seen it connected to a new upgrade. This technique should fix things.
    Empty/corrupt library after upgrade/crash
    Hopefully it's not been too long since you last upgraded iTunes, in fact if you get an empty/incomplete library immediately after upgrading then with the following steps you shouldn't lose a thing or need to do any further housekeeping. In the Previous iTunes Libraries folder should be a number of dated iTunes Library files. Take the most recent of these and copy it into the iTunes folder. Rename iTunes Library.itl as iTunes Library (Corrupt).itl and then rename the restored file as iTunes Library.itl. Start iTunes. Should all be good, bar any recent additions to or deletions from your library.
    See iTunes Folder Watch for a tool to catch up with any changes since the backup file was created.
    When you get it all working make a backup!
    tt2

Maybe you are looking for