当前位置: 首页>>代码示例>>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;未经允许,请勿转载。