1

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.

Community
  • 1
  • 1
AJ.
  • 13,461
  • 19
  • 51
  • 63

3 Answers3

4

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

Serxipc
  • 6,639
  • 9
  • 40
  • 51
3

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);
Community
  • 1
  • 1
AJ.
  • 13,461
  • 19
  • 51
  • 63
0

You can also do it less bold.

  1. use the return value of jEdit.openFile(), this is already the Buffer, no need for getBuffer()
  2. Do not call VFSManager.waitForRequests() which waits for ALL requests to be done, but simply add a BufferListener to the Buffer you got from jEdit.openFile() and do your save call in the bufferLoaded method of this listener :-)
Vampire
  • 35,631
  • 4
  • 76
  • 102