Package org.openide.filesystems

Examples of org.openide.filesystems.FileLock


        if (skeepIfExists && dir.getFileObject(MANIFEST_FILE) != null) {
            return;
        }
        else {
            FileObject manifest = dir.createData(MANIFEST_FILE);
            FileLock lock = manifest.lock();
            try {
                OutputStream os = manifest.getOutputStream(lock);
                try {
                    PrintWriter pw = new PrintWriter(os);
                    pw.println("Manifest-Version: 1.0"); // NOI18N
                    pw.println("X-COMMENT: Main-Class will be added automatically by build"); // NOI18N
                    pw.println(); // safest to end in \n\n due to JRE parsing bug
                    pw.flush();
                } 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

            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

      String s1 = myIDLData.getIdlSource();
     
      if(s1 != null && s1.length() > 0)
        {    
             
              FileLock filelock = null;
              PrintWriter printwriter = null;
                try
                {
                    FileObject fileobject = result.getPrimaryFile();
                    filelock = fileobject.lock();
                    printwriter = new PrintWriter(new OutputStreamWriter(fileobject.getOutputStream(filelock)));
                    DateFormat dateformat = DateFormat.getDateTimeInstance(1, 2);
                    printwriter.println("//\n// " + result.getName() + ".idl\n//\n// Created on " + dateformat.format(new Date()) + "\n// by " + System.getProperty("user.name") + "\n//\n");
                    printwriter.println("\n ");
                    printwriter.println("#ifndef __" + fileobject.getPackageNameExt('_','_') + "__" );    
                    printwriter.println("#define __" + fileobject.getPackageNameExt('_','_') + "__\n" );    
                   
                    printwriter.println(s1);
                    printwriter.println("#endif" );    
                     if(printwriter != null)
                         printwriter.close();
                     if(filelock != null)
                         filelock.releaseLock();
                }
                catch(IOException ioexception)
                {
                }
                OpenCookie open = (OpenCookie) result.getCookie (OpenCookie.class);
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

            text = text.replaceAll(Pattern.quote("${safe_name}"), safeName);
            final String textOut = text;
            fs.runAtomicAction(new FileSystem.AtomicAction() {

                public void run() throws IOException {
                    FileLock lock = file.lock();
                    try {
                        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(file.getOutputStream(lock)));

                        bw.write(textOut);
                        bw.close();
                    } finally {
                        lock.releaseLock();
                    }
                }
            });

        } catch (FileStateInvalidException ex) {
View Full Code Here

        fo.delete();
    }

    private void rename ( String path, String newName ) throws IOException {
        FileObject fo = mfs.getRoot().getFileObject( path );
        FileLock lock = fo.lock();
        try {
            fo.rename( lock, newName, "txt" );
        } finally {
            lock.releaseLock();
        }
    }
View Full Code Here

        for (final FileObject fo : children) {
            InputStream is = null;

            String code = "";
            FileLock lock = null;
            try {
                lock = fo.lock();
                is = fo.getInputStream();
                BufferedReader r = new BufferedReader(new InputStreamReader(is));
                String s;
                StringBuffer sb = new StringBuffer();
                while ((s = r.readLine()) != null) {
                    sb.append(s);
                    sb.append("\n");
                }
                code = sb.toString();

            } catch (FileNotFoundException ex) {
                Exceptions.printStackTrace(ex);
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            } finally {
                try {
                    is.close();
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
                lock.releaseLock();
            }

            String displayName = fo.getName();

View Full Code Here

        }

        public void changed(Filter source) {
            try {
                if (!fileObject.getName().equals(filter.getName())) {
                    FileLock lock = fileObject.lock();
                    fileObject.move(lock, fileObject.getParent(), filter.getName(), "");
                    lock.releaseLock();
                    FileObject newFileObject = fileObject.getParent().getFileObject(filter.getName());
                    fileObject = newFileObject;

                }

                FileLock lock = fileObject.lock();
                OutputStream os = fileObject.getOutputStream(lock);
                Writer w = new OutputStreamWriter(os);
                String s = filter.getCode();
                w.write(s);
                w.close();
                lock.releaseLock();

            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
View Full Code Here

                //Delete original file
                fileObject.delete();

                //Rename
                FileObject tempFileObject = FileUtil.toFileObject(writeFile);
                FileLock lock = tempFileObject.lock();
                tempFileObject.rename(lock, name, ext);
                lock.releaseLock();
            }

        } catch (Exception ex) {
            if (ex instanceof GephiFormatException) {
                throw (GephiFormatException) ex;
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.