Search in sources :

Example 1 with FileAlreadyLockedException

use of org.openide.filesystems.FileAlreadyLockedException in project netbeans-mmd-plugin by raydac.

the class AbstractElement method writeMindMap.

protected static void writeMindMap(final File file, final MindMap map) throws IOException {
    final FileObject fileObject = FileUtil.toFileObject(file);
    FileLock lock = null;
    while (true) {
        try {
            lock = fileObject.lock();
            break;
        } catch (FileAlreadyLockedException ex) {
            delay(500L);
        }
    }
    try {
        final OutputStream out = fileObject.getOutputStream(lock);
        try {
            // NOI18N
            IOUtils.write(map.packToString(), out, "UTF-8");
        } finally {
            IOUtils.closeQuietly(out);
        }
    } finally {
        if (lock != null) {
            lock.releaseLock();
        }
    }
}
Also used : OutputStream(java.io.OutputStream) FileLock(org.openide.filesystems.FileLock) FileObject(org.openide.filesystems.FileObject) FileAlreadyLockedException(org.openide.filesystems.FileAlreadyLockedException)

Aggregations

OutputStream (java.io.OutputStream)1 FileAlreadyLockedException (org.openide.filesystems.FileAlreadyLockedException)1 FileLock (org.openide.filesystems.FileLock)1 FileObject (org.openide.filesystems.FileObject)1