Package org.openide.filesystems

Examples of org.openide.filesystems.FileLock


            }
        }
    }

    private void doPersist() {
        FileLock lock = null;
        ObjectOutputStream ois = null;

        try {
            if (databaseConfigurations != null) {
                databaseConfigurations.delete();
            }

            databaseConfigurations = FileUtil.getConfigRoot().createData("EdgeListDatabase");
            lock = databaseConfigurations.lock();

            ois = new ObjectOutputStream(databaseConfigurations.getOutputStream(lock));
            ois.writeObject(edgeListDatabases);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (ois != null) {
                try {
                    ois.close();
                } catch (IOException e) {
                }
            }
            if (lock != null) {
                lock.releaseLock();
            }
        }
    }
View Full Code Here


                //Delete original file
                fileObject.delete();

                //Rename temp file
                FileObject tempFileObject = FileUtil.toFileObject(writeFile);
                FileLock lock = tempFileObject.lock();
                tempFileObject.rename(lock, name, ext);
                lock.releaseLock();
            } else if (cancel) {
                //Delete temp file
                FileObject tempFileObject = FileUtil.toFileObject(writeFile);
                tempFileObject.delete();
            }
View Full Code Here

            ErrorManager.getDefault().notify(ioe);
        }

        FileObject fo = result.getPrimaryFile();
        if (fo.getExt().equals("java")) {
            FileLock lock = null;
            try {
                PackageRemover.removeDeclaration(FileUtil.toFile(fo));

                // IssueZilla 11986 - rename the FileObject
                // so the JavaNode is resynchronized
                lock = fo.lock();
                if (lock != null) {
                    fo.rename(lock, fo.getName(), fo.getExt());
                }
            }
            catch (IOException ioe) {
                NotifyDescriptor d = new NotifyDescriptor.Message(
                 "Error removing package declaration from file: " +
                 fo.getNameExt() +
                 ". You should manually remove this declaration " +
                 "before building the Parcel Recipe");
                TopManager.getDefault().notify(d);
            }
            finally {
                if (lock != null) {
                    lock.releaseLock();
                }
            }
        }
    }
View Full Code Here

                    final String backupext = String.format("%s~",buildImpl.getExt());   //NOI18N
                    final FileObject oldBackup = buildImpl.getParent().getFileObject(name, backupext);
                    if (oldBackup != null) {
                        oldBackup.delete();
                    }
                    FileLock lock = buildImpl.lock();
                    try {
                        buildImpl.rename(lock, name, backupext);
                    } finally {
                        lock.releaseLock();
                    }
                }
            }
            saveLibrariesLocation();
            // Store properties
View Full Code Here

        }
        return builder;
    }

    protected void writeFile(final FileObject someFile, final CharSequence content) throws IOException {
        FileLock lock;
        try {
            lock = someFile.lock();
        } catch (FileAlreadyLockedException e) {
            return;
        }
        Writer to = null;
        try {
            to = new OutputStreamWriter(someFile.getOutputStream(lock), FileEncodingQuery.getEncoding(someFile));
            to.write(content.toString());
        } finally {
            IOUtils.closeQuietly(to);
            lock.releaseLock();
        }
    }
View Full Code Here

            while ((ent = zip.getNextEntry()) != null) {
                if (ent.isDirectory()) {
                    FileUtil.createFolder(targetFolder, ent.getName());
                } else {
                    final FileObject destFile = FileUtil.createData(targetFolder,ent.getName());
                    final FileLock lock = destFile.lock();
                    try {
                        final OutputStream out = destFile.getOutputStream(lock);
                        try {
                            FileUtil.copy(zip, out);
                        } finally {
                            out.close();
                        }
                    } finally {
                        lock.releaseLock();
                    }
                }
            }
        } finally {
            zip.close();
View Full Code Here

     * Save an XML config file to a named path.
     * If the file does not yet exist, it is created.
     */
    private static void saveXml(Document doc, FileObject dir, String path) throws IOException {
        FileObject xml = FileUtil.createData(dir, path);
        FileLock lock = xml.lock();
        try {
            OutputStream os = xml.getOutputStream(lock);
            try {
                XMLUtil.write(doc, os, "UTF-8"); // NOI18N
            } finally {
                os.close();
            }
        } finally {
            lock.releaseLock();
        }
    }
View Full Code Here

            ErrorManager.getDefault().notify(ioe);
        }

        FileObject fo = result.getPrimaryFile();
        if (fo.getExt().equals("java")) {
            FileLock lock = null;
            try {
                PackageRemover.removeDeclaration(FileUtil.toFile(fo));

                // IssueZilla 11986 - rename the FileObject
                // so the JavaNode is resynchronized
                lock = fo.lock();
                if (lock != null) {
                    fo.rename(lock, fo.getName(), fo.getExt());
                }
            }
            catch (IOException ioe) {
                NotifyDescriptor d = new NotifyDescriptor.Message(
                 "Error removing package declaration from file: " +
                 fo.getNameExt() +
                 ". You should manually remove this declaration " +
                 "before building the Parcel Recipe");
                TopManager.getDefault().notify(d);
            }
            finally {
                if (lock != null) {
                    lock.releaseLock();
                }
            }
        }
    }
View Full Code Here

                    line = reader.readLine();
                }
            } finally {
                reader.close();
            }
            FileLock lock = target.lock();
            try {
                BufferedWriter writer = new BufferedWriter(
                        new OutputStreamWriter(target.getOutputStream(lock), ENCODING));
                try {
                    writer.write(buffer.toString());
                } finally {
                    writer.close();
                }
            } finally {
                lock.releaseLock();
            }
            return target;
        }
View Full Code Here

        writeFile(file, content, ENCODING);
    }

    //Write the content of the file:
    private static void writeFile(FileObject file, String content, String encoding) throws IOException {
        FileLock lock = file.lock();
        try {
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(file.getOutputStream(lock), encoding));
            try {
                bw.write(content);
            } finally {
                bw.close();
            }
        } finally {
            lock.releaseLock();
        }
    }
View Full Code Here

TOP

Related Classes of org.openide.filesystems.FileLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.