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


Java FileObject.rename方法代碼示例

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


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

示例1: testRename

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testRename() throws Exception {
    Layer l = new Layer("    <folder name=\"folder1\">\n        <file name=\"file1.txt\">\n            <attr name=\"a\" stringvalue=\"v\"/>\n        </file>\n    </folder>\n");
    FileSystem fs = l.read();
    FileObject f = fs.findResource("folder1");
    assertNotNull(f);
    FileLock lock = f.lock();
    f.rename(lock, "folder2", null);
    lock.releaseLock();
    f = fs.findResource("folder2/file1.txt");
    assertNotNull(f);
    lock = f.lock();
    f.rename(lock, "file2.txt", null);
    lock.releaseLock();
    assertEquals("#63989: correct rename handling", "    <folder name=\"folder2\">\n        <file name=\"file2.txt\">\n            <attr name=\"a\" stringvalue=\"v\"/>\n        </file>\n    </folder>\n", l.write());
    // XXX should any associated ordering attrs also be renamed? might be pleasant...
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:WritableXMLFileSystemTest.java

示例2: testImplsRename

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testImplsRename() 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.getExt(), toRename.getName());
        assertEquals(1,iListener.implsRenameCalls);
        assertEquals(1,iListener.renameImplCalls);
    } finally {
        if (lock != null) {
            iListener.setLock(null);
            lock.releaseLock();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ProvidedExtensionsTest.java

示例3: testDuplicateFileObject130998

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
/** Tests it is not possible to create duplicate FileObject for the same path.
 * - create FO1
 * - create FO2
 * - delete FO1 => FO1 is invalid now
 * - rename FO2 to FO1
 * - rename FO1 to FO1 => FO1 still invalid
 * - try to write to FO1.getOutputStream() => it should not be possible because FO1 is still invalid
 */
public void testDuplicateFileObject130998() throws IOException {
    clearWorkDir();
    FileObject testFolder = FileUtil.toFileObject(getWorkDir());
    FileObject fileObject1 = testFolder.createData("fileObject1");
    FileObject fileObject2 = testFolder.createData("fileObject2");
    fileObject1.delete();
    assertFalse("fileObject1 should be invalid after delete.", fileObject1.isValid());

    FileLock lock = fileObject2.lock();
    fileObject2.rename(lock, fileObject1.getName(), null);
    lock.releaseLock();
    assertTrue("fileObject2 should be valid.", fileObject2.isValid());

    lock = fileObject1.lock();
    fileObject1.rename(lock, fileObject1.getName(), null);
    lock.releaseLock();
    assertFalse("fileObject1 should remain invalid after rename.", fileObject1.isValid());
    
    OutputStream os = fileObject1.getOutputStream();
    assertTrue("Valid file", FileUtil.toFile(fileObject1).exists());
    assertFalse("Invalid file object", fileObject1.isValid());
    assertNotNull("Since #211483 it is possible to obtain OutputStream for valid file/invalid fo", os);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:FileObjTest.java

示例4: testRenameWithAttributes

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testRenameWithAttributes() throws Exception {
    final FileObject workDirFo = FileBasedFileSystem.getFileObject(getWorkDir());
    FileObject folder = workDirFo.createFolder("a");
    folder.createData("non.empty");
    folder.setAttribute("name", "jmeno");
    assertEquals("jmeno", folder.getAttribute("name"));
    FileLock lock = folder.lock();
    folder.rename(lock, "b", null);
    lock.releaseLock();
    assertEquals("Name is not b", "b", folder.getNameExt());
    WeakReference<?> ref = new WeakReference<FileObject>(folder);
    folder = null;
    assertGC("Folder can disappear", ref);
    folder = workDirFo.getFileObject("b");
    assertNotNull("Folder b found", folder);
    assertEquals("The attribute remains even after rename", "jmeno", folder.getAttribute("name"));
    assertEquals("One children", 1, folder.getChildren().length);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:FolderObjTest.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: testCaseSensitiveFolderRename

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testCaseSensitiveFolderRename() throws Exception {
    FileObject parent = root.getFileObject("testdir/mountdir10");
    List<FileObject> arr = Arrays.asList(parent.getChildren());
    final String up = parent.getName().toUpperCase();
    FileLock lock = parent.lock();
    try {
        parent.rename(lock, up, null);
    } finally {
        lock.releaseLock();
    }
    assertEquals("Capital name", up, parent.getNameExt());
    File real = FileUtil.toFile(parent);
    assertNotNull("Real file exists", real);
    assertEquals("It is capitalized too", up, real.getName());
    
    List<FileObject> now = Arrays.asList(parent.getChildren());
    assertEquals("Same children: ", arr, now);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:BaseFileObjectTestHid.java

示例7: testSimulateLocalizedBundlePackageRefactoring

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testSimulateLocalizedBundlePackageRefactoring() throws Exception {
    NbModuleProject p = generateStandaloneModule("module1");
    SingleModuleProperties props = loadProperties(p);
    assertEquals("display name from ProjectInformation", "Testing Module",
            ProjectUtils.getInformation(p).getDisplayName());
    assertEquals("display name from LocalizedBundleInfo", "Testing Module",
            props.getBundleInfo().getDisplayName());
    
    // rename package
    FileObject pDir = p.getProjectDirectory();
    FileObject pkg = pDir.getFileObject("src/org/example/module1");
    FileLock lock = pkg.lock();
    pkg.rename(lock, "module1Renamed", null);
    lock.releaseLock();
    System.gc();    // no more random
    FileObject manifestFO = pDir.getFileObject("manifest.mf");

    // change manifest
    EditableManifest mf = Util.loadManifest(manifestFO);
    mf.setAttribute(ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE, "org/example/module1Renamed/resources/Bundle.properties", null);
    Util.storeManifest(manifestFO, mf);
    simulatePropertiesOpening(props, p);
    
    // make sure that properties are not damaged
    assertEquals("display name was refreshed in ProjectInformation", "Testing Module",
            ProjectUtils.getInformation(p).getDisplayName());
    assertEquals("display name was refreshed in LocalizedBundleInfo", "Testing Module",
            props.getBundleInfo().getDisplayName());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:SingleModulePropertiesTest.java

示例8: testSimulateIllLocalizedBundlePackageRefactoring_67961

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testSimulateIllLocalizedBundlePackageRefactoring_67961() throws Exception {
    NbModuleProject p = generateStandaloneModule("module1");
    SingleModuleProperties props = loadProperties(p);
    assertEquals("display name from ProjectInformation", "Testing Module",
            ProjectUtils.getInformation(p).getDisplayName());
    assertEquals("display name from LocalizedBundleInfo", "Testing Module",
            props.getBundleInfo().getDisplayName());
    
    // change manifest (will fire a change event before the package is actually renamed)
    FileObject pDir = p.getProjectDirectory();
    FileObject manifestFO = pDir.getFileObject("manifest.mf");
    EditableManifest mf = Util.loadManifest(manifestFO);
    mf.setAttribute(ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE, "org/example/module1Renamed/resources/Bundle.properties", null);
    Util.storeManifest(manifestFO, mf);
    
    // rename package
    FileObject pkg = pDir.getFileObject("src/org/example/module1");
    FileLock lock = pkg.lock();
    pkg.rename(lock, "module1Renamed", null);
    lock.releaseLock();
    
    simulatePropertiesOpening(props, p);
    
    // make sure that properties are not damaged
    assertEquals("display name was refreshed in ProjectInformation", "Testing Module",
            ProjectUtils.getInformation(p).getDisplayName());
    assertEquals("display name was refreshed in LocalizedBundleInfo", "Testing Module",
            props.getBundleInfo().getDisplayName());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:SingleModulePropertiesTest.java

示例9: rename

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
@NonNull
private FileObject rename(
        @NonNull final FileObject root,
        @NonNull final String name) throws IOException {
    final String simpleName = FileObjects.stripExtension(name);
    final String ext = FileObjects.getExtension(name);
    final FileObject file = FileUtil.getArchiveFile(root);
    final FileLock lck = file.lock();
    try {
        file.rename(lck, simpleName, ext);
    } finally {
        lck.releaseLock();
    }
    return FileUtil.getArchiveRoot(file);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:ModuleNamesTest.java

示例10: renameFO

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
private void renameFO(File from, File to) throws DataObjectNotFoundException, IOException {
    // ensure parent is known by filesystems
    // otherwise no event will be thrown
    FileObject parent = FileUtil.toFileObject(from.getParentFile());
    FileObject foFrom = FileUtil.toFileObject(from);
    FileLock lock = foFrom.lock();
    try {
        foFrom.rename(lock, to.getName(), null);
    } finally {
        lock.releaseLock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:FilesystemInterceptorTest.java

示例11: testFilesScannedAfterRenameOfFolder193243

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testFilesScannedAfterRenameOfFolder193243() throws Exception {
    final TestHandler handler = new TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests");
    logger.setLevel (Level.FINEST);
    logger.addHandler(handler);
    final FileObject testFo = FileUtil.createData(this.srcRootWithFiles1, "rename/A.foo");
    final MutableClassPathImplementation mcpi1 = new MutableClassPathImplementation ();
    mcpi1.addResource(this.srcRootWithFiles1);
    final ClassPath cp1 = ClassPathFactory.createClassPath(mcpi1);
    globalPathRegistry_register(SOURCES,new ClassPath[]{cp1});
    assertTrue (handler.await());
    indexerFactory.indexer.setExpectedFile(new URL[]{new URL(this.srcRootWithFiles1.toURL()+"renamed/A.foo")}, new URL[]{testFo.toURL()}, new URL[0]);
    eindexerFactory.indexer.setExpectedFile(new URL[0], new URL[]{testFo.toURL()}, new URL[0]);
    final FileObject parent = testFo.getParent();
    final FileLock lock = parent.lock();
    try {
        parent.rename(lock, "renamed", null);
    } finally {
        lock.releaseLock();
    }
    assertTrue(indexerFactory.indexer.awaitDeleted(TIME));
    assertTrue(eindexerFactory.indexer.awaitDeleted());
    assertTrue(indexerFactory.indexer.awaitIndex(TIME));
    assertTrue(eindexerFactory.indexer.awaitIndex());
    assertEquals(0, eindexerFactory.indexer.getIndexCount());
    assertEquals(1, eindexerFactory.indexer.getDeletedCount());
    assertEquals(0, eindexerFactory.indexer.getDirtyCount());
    assertEquals(1, indexerFactory.indexer.getIndexCount());
    assertEquals(1, indexerFactory.indexer.getDeletedCount());
    assertEquals(0, indexerFactory.indexer.getDirtyCount());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:RepositoryUpdaterTest.java

示例12: removeUnwantedFile

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
private void removeUnwantedFile() throws IOException {
//        rename tabIndex.html
        FileObject indexFile = webRoot.getFileObject("index.html");
        if (indexFile != null) {
            FileLock lock = indexFile.lock();
            indexFile.rename(lock, "index_" + new Date().getTime(), "html");
            lock.releaseLock();
        }
    }
 
開發者ID:jeddict,項目名稱:hipee,代碼行數:10,代碼來源:Angular2Generator.java

示例13: testManifestChanges

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testManifestChanges() throws IOException {
    final CompilerOptionsQueryImplementation q = new AutomaticModuleNameCompilerOptionsQueryImpl(
            project.getUpdateHelper().getAntProjectHelper(),
            project.getEvaluator(),
            srcRoots,
            ProjectProperties.MANIFEST_FILE);
    final CompilerOptionsQueryImplementation.Result r = q.getOptions(srcRoots.getRoots()[0]);
    assertNotNull(r);
    assertTrue(r.getArguments().isEmpty());
    updateManifest(Collections.singletonMap("Automatic-Module-Name", "org.me.foo"));    //NOI18N
    assertNotNull(getManifest());
    assertNotNull(r);
    assertEquals(
            Collections.singletonList("-XDautomatic-module-name:org.me.foo"),    //NOI18N
            r.getArguments());
    updateManifest(Collections.singletonMap("Automatic-Module-Name", "org.me.boo"));    //NOI18N
    assertEquals(
            Collections.singletonList("-XDautomatic-module-name:org.me.boo"),    //NOI18N
            r.getArguments());
    final FileObject mf = getManifest();
    try (FileLock lck = mf.lock()) {
        mf.rename(lck, "manifest", "bak"); //NOI18N
    }
    assertTrue(r.getArguments().isEmpty());
    try (FileLock lck = mf.lock()) {
        mf.rename(lck, "manifest", "mf"); //NOI18N
    }
    assertEquals(
            Collections.singletonList("-XDautomatic-module-name:org.me.boo"),    //NOI18N
            r.getArguments());
    mf.delete();
    assertTrue(r.getArguments().isEmpty());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:AutomaticModuleNameCompilerOptionsQueryImplTest.java

示例14: renameFO

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
private void renameFO(File from, File to) throws DataObjectNotFoundException, IOException {
    // ensure parent is known by filesystems
    // otherwise no event will be thrown
    FileObject parent = FileUtil.toFileObject(from.getParentFile());

    FileObject foFrom = FileUtil.toFileObject(from);
    FileLock lock = foFrom.lock();
    try {
        foFrom.rename(lock, to.getName(), null);
    } finally {
        lock.releaseLock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:InteceptorTest.java

示例15: testFileCreatedLockedRenamedDeleted

import org.openide.filesystems.FileObject; //導入方法依賴的package包/類
public void testFileCreatedLockedRenamedDeleted() throws IOException {
    inteceptor.moveHandler = moveHandler;
    inteceptor.deleteHandler = deleteHandler;
    FileObject fo = getVersionedFolder();
    logHandler.clear();
    
    fo = fo.createData("deleteme.txt");
    VCSFileProxy proxy = VCSFileProxy.createFileProxy(fo);
    FileLock lock = fo.lock();
    fo.rename(lock, "deleteme", "now");
    lock.releaseLock();
    VCSFileProxy proxy2 = VCSFileProxy.createFileProxy(fo);
    fo.delete();
    assertTrue(inteceptor.getBeforeCreateFiles().contains(proxy));
    assertTrue(inteceptor.getDoCreateFiles().contains(proxy));
    assertTrue(inteceptor.getCreatedFiles().contains(proxy));
    assertTrue(inteceptor.getBeforeEditFiles().contains(proxy));
    assertTrue(inteceptor.getBeforeMoveFiles().contains(proxy));
    assertTrue(inteceptor.getAfterMoveFiles().contains(proxy));
    assertTrue(inteceptor.getBeforeDeleteFiles().contains(proxy2));
    assertTrue(inteceptor.getDoDeleteFiles().contains(proxy2));
    assertTrue(inteceptor.getDeletedFiles().contains(proxy2));
    
    assertInterceptedCalls(
        f(beforeCreateFormat, proxy.getParentFile(), proxy.getName(), false),
        f(createSuccessFormat, proxy),
        f(fileLockedFormat, proxy),
        f(getRenameHandlerFormat, proxy, proxy2.getName()),
        f(moveHandleFormat, proxy, proxy2),
        f(afterMoveFormat, proxy, proxy2),
        f(fileLockedFormat, proxy),
        f(getDeleteHandlerFormat, proxy2),
        f(deleteHandleFormat, proxy2),
        f(deleteSuccessFormat, proxy2)
    );
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:VCSInterceptorTestCase.java


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