views:

556

answers:

2

I have a JEdit (BeanShell) macro which opens a specific file then immediately saves the file to my c:\temp folder (so that I don't accidentally update the real file).

Here is the bean shell code:

logFilePath = "c:\\temp\\aj.txt";
jEdit.openFile( view , logFilePath );
_buffer = jEdit.getBuffer(logFilePath);
_buffer.save(view,"c:\\temp\\backup.txt",true);

This gives me the following error:

I/O Error
Each buffer can only execute one input/output operation at a time.  
Please wait until the current operation finishes 
(or abort it in the I/O progress monitor) before starting another one.

I have tried adding a while loop to wait until buffer.isLoaded() is true, but that just goes into an infinite loop.
What does seem to work is popping up a message box ( Macros.message ). However, I really don't want to have this unnecessary dialogue.

I don't know much java, so please tell me if I'm making a rookie mistake.

Update:

Added my own answer to show the code pointed to from Serhii's answer.

+3  A: 

You can try this solution, calling VFSManager.waitForRequests();.

Serhii
thanks. works great. :)
AJ
+2  A: 

This Works

This is the code pointed to by Serhii's answer, above.

Add VFSManager.waitForRequests(); after the jEdit.openFile() command.

Full Code

logFilePath = "c:\\temp\\aj.txt";
jEdit.openFile( view , logFilePath );

VFSManager.waitForRequests();

/* 
    VFSManager.waitForRequests();

    jEdit waits then for the file to be completely loaded before continuing 
    ... It's designed for waiting on all 'pending I/O requests'".
*/

_buffer = jEdit.getBuffer(logFilePath);
_buffer.save(view,"c:\\temp\\backup.txt",true);
AJ