當前位置: 首頁>>代碼示例>>Java>>正文


Java FileObject.lock方法代碼示例

本文整理匯總了Java中org.openide.filesystems.FileObject.lock方法的典型用法代碼示例。如果您正苦於以下問題:Java FileObject.lock方法的具體用法?Java FileObject.lock怎麽用?Java FileObject.lock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openide.filesystems.FileObject的用法示例。


在下文中一共展示了FileObject.lock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createSource

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
private FileObject createSource(
        @NonNull final FileObject root,
        @NonNull final String fqn,
        @NonNull final String content) throws IOException {
    final FileObject file = FileUtil.createData(root, fqn.replace('.', '/')+"."+JavaDataLoader.JAVA_EXTENSION);   //NOI18N
    final FileLock lck = file.lock();
    try {
        final PrintWriter out = new PrintWriter(new OutputStreamWriter(file.getOutputStream(lck),"UTF-8"));    //NOI18N
        try {
            out.print(content);
        } finally {
            out.close();
        }
    } finally {
        lck.releaseLock();
    }
    return file;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:ReferencesCountTest.java

示例2: createManifest

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
/**
 * Create a new application manifest file with minimal initial contents.
 * @param dir the directory to create it in
 * @throws IOException in case of problems
 */
private static void createManifest(final FileObject dir, final String manifestFile) throws IOException {

    FileObject manifest = dir.createData(manifestFile);
    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();
    }

}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:J2SEProjectFactory.java

示例3: serialize

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
@Override
public void serialize() {
    try {
        FileObject writeTo = getServerListFile();
        FileLock lock = writeTo.lock();
        try {
            ObjectOutputStream str = new ObjectOutputStream(writeTo.getOutputStream(lock));
            try {
                str.writeObject(servers.getList());
            } finally {
                str.close();
            }
        } finally {
            lock.releaseLock();
        }

    } catch (IOException ioe) {
        Exceptions.printStackTrace(ioe);
    }
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:21,代碼來源:DefaultServersManager.java

示例4: copySrcToDest

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
private static void copySrcToDest( FileObject srcFile, FileObject destFile) throws IOException {
    if (destFile != null && !srcFile.isFolder()) {
        InputStream is = null;
        OutputStream os = null;
        FileLock fl = null;
        try {
            is = srcFile.getInputStream();
            fl = destFile.lock();
            os = destFile.getOutputStream(fl);
            FileUtil.copy(is, os);
        } finally {
            if (is != null) {
                is.close();
            }
            if (os != null) {
                os.close();
            }
            if (fl != null) {
                fl.releaseLock();
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:CopyResourcesOnSave.java

示例5: testMimeTypeChange

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testMimeTypeChange() throws IOException {
    clearWorkDir();
    final FileObject file = createFileObject("empty.foo", "", "\n");
    final Source source = Source.create(file);
    assertNotNull("No Source for " + file, source);
    assertSame("Wrong FileObject", file, source.getFileObject());
    assertSame("Inconsistent Source.create(FileObject)", source, Source.create(file));
    final FileLock lock = file.lock();
    try {
        file.rename(lock, "empty", "txt");  //NOI18N
    } finally {
        lock.releaseLock();
    }
    final Source source2 = Source.create(file);
    assertNotNull("No Source for " + file, source2);
    assertSame("Wrong FileObject", file, source2.getFileObject());
    assertNotSame("Inconsistent Source.create(FileObject)", source, source2);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:SourceTest.java

示例6: testImplsCaseOnlyRename

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testImplsCaseOnlyRename() throws IOException {
    FileObject fo = FileUtil.toFileObject(getWorkDir());
    assertNotNull(fo);
    assertNotNull(iListener);
    FileObject toRename = fo.createData("aa");
    assertNotNull(toRename);
    
    iListener.clear();
    FileLock lock = toRename.lock();
    iListener.setLock(lock);
    try {
        assertEquals(0,iListener.implsRenameCalls);
        assertEquals(0,iListener.renameImplCalls);
        iListener.setImplsRenameRetVal(true);
        assertTrue(toRename.isValid());
        assertNull(toRename.getParent().getFileObject(toRename.getExt(), toRename.getName()));
        toRename.rename(lock,toRename.getName().toUpperCase(), toRename.getExt().toUpperCase());
        assertEquals(1,iListener.implsRenameCalls);
        assertEquals(1,iListener.renameImplCalls);
    } finally {
        if (lock != null) {
            iListener.setLock(null);
            lock.releaseLock();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ProvidedExtensionsTest.java

示例7: writeIntoFile

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
private void writeIntoFile(FileObject file, String what) throws Exception {
    FileLock lock = file.lock();
    OutputStream out = file.getOutputStream(lock);
    
    try {
        out.write(what.getBytes());
    } finally {
        out.close();
        lock.releaseLock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:SuspiciousNamesCombinationTest.java

示例8: createSettings

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
static FileObject createSettings (FileObject root, String name) throws IOException {
    FileObject set = FileUtil.createData (root, name);

    FileLock lock = set.lock ();
    java.io.PrintStream os = new java.io.PrintStream (set.getOutputStream (lock));
    
    os.println ("<?xml version=\"1.0\"?>");
    os.println ("<!DOCTYPE settings PUBLIC \"-//NetBeans//Test//EN\" \"http://www.netbeans.org/dtds/sessionsettings-1_0.dtd\">");
    os.println ("<lkp version=\"1.0\">");
    os.println ("</lkp>");
    
    os.close ();
    lock.releaseLock();
    return set;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:FileEntityResolverDeadlock54971Test.java

示例9: testDeadlock208663

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testDeadlock208663() throws Exception {
    CompileTuple ct = files.iterator().next();
    final FileObject fo = URLMapper.findFileObject(ct.indexable.getURL());
    final FileLock lck = fo.lock();
    try {
        final OutputStream out = new BufferedOutputStream(fo.getOutputStream(lck));
        try {
            for (int i = 0; i<101; i++) {
                out.write('a');
            }
        } finally {
            out.close();
        }
    } finally {
        lck.releaseLock();
    }
    
    JavaIndexerWorker.TEST_DO_PREFETCH = true;
    JavaIndexerWorker.BUFFER_SIZE = 100;
    final LogHandler handler = new LogHandler();
    handler.expect("Using concurrent iterator, {0} workers");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            ct = pf.next();
            assertNotNull(getCache(ct.jfo));
            got.offer(ct);
            pf.remove();
            assertNull(getCache(ct.jfo));
        }
        assertCollectionsEqual(files,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:41,代碼來源:SourcePrefetcherTest.java

示例10: createFileWithSubstitutions

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
static void createFileWithSubstitutions(
        final FileObject sourceFO,
        final FileObject targetFO,
        final Map<String,String> tokens) throws IOException {
    FileLock lock = targetFO.lock();
    try {
        copyAndSubstituteTokens(sourceFO.getURL(), lock, targetFO, tokens);
    } finally {
        lock.releaseLock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:LanguagesDataObject.java

示例11: writeData

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
/** Writes data from asociated mode to the xml representation */
void writeData (ModeConfig mc, InternalConfig ic) throws IOException {
    final StringBuffer buff = fillBuffer(mc, ic);
    synchronized (RW_LOCK) {
        FileObject cfgFOOutput = getConfigFOOutput();
        FileLock lock = null;
        OutputStream os = null;
        OutputStreamWriter osw = null;
        try {
            lock = cfgFOOutput.lock();
            os = cfgFOOutput.getOutputStream(lock);
            osw = new OutputStreamWriter(os, "UTF-8"); // NOI18N
            osw.write(buff.toString());
            /*log("-- DUMP Mode:");
            log(buff.toString());*/
        } finally {
            try {
                if (osw != null) {
                    osw.close();
                }
            } catch (IOException exc) {
                Logger.getLogger(ModeParser.class.getName()).log(Level.INFO, null, exc);
            }
            if (lock != null) {
                lock.releaseLock();
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:ModeParser.java

示例12: testCannotLockReadOnlyFile

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testCannotLockReadOnlyFile() throws Exception {
    clearWorkDir();
    final File wDir = getWorkDir();
    final File data = new File(wDir,"c.data");
    data.createNewFile();
    data.setReadOnly();
    FileObject fd = FileUtil.toFileObject(data);
    try {
        FileLock lock = fd.lock();
        fail("Shall not be possible to create a lock: " + lock);
    } catch (IOException ex) {
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:BaseFileObjectTestHid.java

示例13: writeInstance

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
private static Object writeInstance (final FileObject folder, final String name, final Object inst) throws IOException {
    class W implements FileSystem.AtomicAction {
        public Object create;
        
        public void run () throws IOException {
            FileObject fo = FileUtil.createData (folder, name);
            FileLock lock = fo.lock ();
            ObjectOutputStream oos = new ObjectOutputStream (fo.getOutputStream (lock));
            oos.writeObject (inst);
            oos.close ();
            lock.releaseLock ();
            
            DataObject obj = DataObject.find (fo);
            InstanceCookie ic = obj.getCookie(InstanceCookie.class);
            
            assertNotNull ("Cookie created", ic);
            try {
                create = ic.instanceCreate ();
                assertEquals ("The same instance class", inst.getClass(), create.getClass ());
            } catch (ClassNotFoundException ex) {
                fail (ex.getMessage ());
            }
        }
    }
    W w = new W ();
    folder.getFileSystem ().runAtomicAction (w);
    return w.create;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:ToolbarPoolTest.java

示例14: deleteFO

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
private void deleteFO (File toDelete) throws DataObjectNotFoundException, IOException {
    FileObject fo = FileUtil.toFileObject(toDelete);
    assertNotNull(fo);
    FileLock lock = fo.lock();
    try {
        fo.delete(lock);
    } finally {
        lock.releaseLock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:InterceptorTest.java

示例15: deleteImpl

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
private void deleteImpl (FileObject mfo, FileSystem fsLayer) throws IOException {
    FileObject fo = fsLayer.findResource (mfo.getPath());
    if (fo != null) {
        FileLock lock = null;
        try {
            lock = fo.lock ();
            fo.delete (lock);
        } finally {
            if (lock != null)
                lock.releaseLock ();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:FileStateManager.java


注:本文中的org.openide.filesystems.FileObject.lock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。