当前位置: 首页>>代码示例>>Java>>正文


Java FileObject.createData方法代码示例

本文整理汇总了Java中org.openide.filesystems.FileObject.createData方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.createData方法的具体用法?Java FileObject.createData怎么用?Java FileObject.createData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.filesystems.FileObject的用法示例。


在下文中一共展示了FileObject.createData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTestFile

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Create an in-memory file with simple string content.
 *
 * @param content Content of the file.
 */
public FileObject createTestFile(String content) throws IOException {

    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = root.createData(TEST_FILE_NAME);

    OutputStream os = fo.getOutputStream();
    try {
        OutputStreamWriter osw = new OutputStreamWriter(os, TEST_FILE_ENC);
        try {
            osw.write(content);
        } finally {
            osw.flush();
            osw.close();
        }
    } finally {
        os.close();
    }
    return fo;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:MatchingObjectTest.java

示例2: deleteFolderTree

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private void deleteFolderTree(FileObject deleteFolder, final VCSFileProxy deleteProxy) throws IOException {
    FileObject folder1 = deleteFolder.createFolder("folder1");
    FileObject folder2 = folder1.createFolder("folder2");
    FileObject folder3 = folder2.createFolder("folder3");
    
    FileObject fo3 = folder3.createData("file");
    FileObject fo2 = folder2.createData("file");
    FileObject fo1 = folder1.createData("file");
    FileObject fo0 = deleteFolder.createData("file");
    logHandler.clear();
    
    deleteFolder.delete();
    
    assertTrue(!inteceptor.getBeforeDeleteFiles().contains(VCSFileProxy.createFileProxy(folder1)));
    assertTrue(!inteceptor.getBeforeDeleteFiles().contains(VCSFileProxy.createFileProxy(folder2)));
    assertTrue(!inteceptor.getBeforeDeleteFiles().contains(VCSFileProxy.createFileProxy(folder3)));
    assertTrue(!inteceptor.getBeforeDeleteFiles().contains(VCSFileProxy.createFileProxy(fo1)));
    assertTrue(!inteceptor.getBeforeDeleteFiles().contains(VCSFileProxy.createFileProxy(fo2)));
    assertTrue(!inteceptor.getBeforeDeleteFiles().contains(VCSFileProxy.createFileProxy(fo3)));
    assertTrue(!inteceptor.getBeforeDeleteFiles().contains(VCSFileProxy.createFileProxy(fo0)));
    assertFalse(deleteFolder.isValid());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:VCSInterceptorTestCase.java

示例3: 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
 */
static void createManifest(final FileObject dir, final boolean skeepIfExists) throws IOException {
    if (!skeepIfExists || dir.getFileObject(MANIFEST_FILE) == null) {
        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();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:JavaFXProjectWizardIterator.java

示例4: takeSnapshotHit

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private String takeSnapshotHit() {        
    LoadedSnapshot loadedSnapshot = null;
    String snapshotFilename = null;
    loadedSnapshot = takeSnapshot();

    if (loadedSnapshot != null) {
        try {
            FileObject snapshotDirectory = getSnapshotDirectory();
            FileObject profFile = snapshotDirectory.createData(ResultsManager.getDefault()
                                                                             .getDefaultSnapshotFileName(loadedSnapshot),
                                                               ResultsManager.SNAPSHOT_EXTENSION);
            ResultsManager.getDefault().saveSnapshot(loadedSnapshot, profFile); // Also updates list of snapshots in ProfilerControlPanel2
            snapshotFilename = FileUtil.toFile(profFile).toURI().toURL().toExternalForm();
        } catch (IOException e) {
            ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
        }
    }

    return (snapshotFilename == null) ? Bundle.TriggeredTakeSnapshotProfilingPoint_NoDataAvailableMsg() : snapshotFilename;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:TriggeredTakeSnapshotProfilingPoint.java

示例5: getClassFile

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private synchronized FileObject getClassFile () throws IOException {
    FileObject fo = this.execTestDir.getFileObject("test/Test.class");
    if (fo == null) {
        fo = execTestDir.createFolder("test");
        fo = fo.createData("Test","class");
        FileLock lock = fo.lock();
        try {
            DataOutputStream out = new DataOutputStream (fo.getOutputStream(lock));
            try {
                out.write(CLASS_FILE_DATA);
                out.flush();
            } finally {
                out.close();
            }
        } finally {
            lock.releaseLock();
        }
    }
    return fo;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DefaultClassPathProviderTest.java

示例6: overwriteDBSchema

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Overwrites <code>dbschemaFile</code> with the contents of
 * <code>schemaElement</code>.
 */
private static void overwriteDBSchema(SchemaElement schemaElement, FileObject dbschemaFile, DBIdentifier dbschemaName) throws IOException {
    try {
        schemaElement.setName(dbschemaName);
    } catch (DBException e) {
        IOException ioe = new IOException(e.getMessage());
        ioe.initCause(e);
        throw ioe;
    }

    // cannot just overwrite the file, DBSchemaDataObject would not
    // notice the file has changed.
    FileObject parent = dbschemaFile.getParent();
    String fileName = dbschemaFile.getName();
    String fileExt = dbschemaFile.getExt();
    dbschemaFile.delete();
    FileObject newDBSchemaFile = parent.createData(fileName, fileExt);

    writeSchemaElement(schemaElement, newDBSchemaFile);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:DBSchemaManager.java

示例7: testGeneratedSources

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testGeneratedSources() throws Exception { // #187595
    TestFileUtils.writeFile(d,
            "pom.xml",
            "<project xmlns='http://maven.apache.org/POM/4.0.0'>" +
            "<modelVersion>4.0.0</modelVersion>" +
            "<groupId>grp</groupId>" +
            "<artifactId>art</artifactId>" +
            "<packaging>jar</packaging>" +
            "<version>0</version>" +
            "</project>");
    FileObject src = FileUtil.createFolder(d, "src/main/java");
    FileObject gsrc = FileUtil.createFolder(d, "target/generated-sources/xjc");
    gsrc.createData("Whatever.class");
    FileObject tsrc = FileUtil.createFolder(d, "src/test/java");
    FileObject gtsrc = FileUtil.createFolder(d, "target/generated-test-sources/jaxb");
    gtsrc.createData("Whatever.class");
    SourceGroup[] grps = ProjectUtils.getSources(ProjectManager.getDefault().findProject(d)).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assertEquals(2, grps.length);
    assertEquals(src, grps[0].getRootFolder());
    assertEquals(tsrc, grps[1].getRootFolder());
    grps = ProjectUtils.getSources(ProjectManager.getDefault().findProject(d)).getSourceGroups(MavenSourcesImpl.TYPE_GEN_SOURCES);
    assertEquals(2, grps.length);
    assertEquals(gsrc, grps[0].getRootFolder());
    assertEquals(gtsrc, grps[1].getRootFolder());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:MavenSourcesImplTest.java

示例8: createDocuments

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
protected Document[] createDocuments(String... fileName) {
    try {
        List<Document> docs = new ArrayList<>();
        FileSystem memFS = FileUtil.createMemoryFileSystem();
        for (String fName : fileName) {

            //we may also create folders
            StringTokenizer items = new StringTokenizer(fName, "/");
            FileObject fo = memFS.getRoot();
            while(items.hasMoreTokens()) {
                String item = items.nextToken();
                if(items.hasMoreTokens()) {
                    //folder
                    fo = fo.createFolder(item);
                } else {
                    //last, create file
                    fo = fo.createData(item);
                }
                assertNotNull(fo);
            }
            
            DataObject dobj = DataObject.find(fo);
            assertNotNull(dobj);

            EditorCookie cookie = dobj.getCookie(EditorCookie.class);
            assertNotNull(cookie);

            Document document = (Document) cookie.openDocument();
            assertEquals(0, document.getLength());

            docs.add(document);

        }
        return docs.toArray(new Document[]{});
    } catch (Exception ex) {
        throw new IllegalStateException("Error setting up tests", ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:TestBase.java

示例9: testCanUseFileName

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testCanUseFileName() throws Exception {
    FileObject d = FileUtil.toFileObject(getWorkDir());
    FileObject p1 = d.getFileObject("project1");
    assertNotNull(p1);
    assertNull("normal file addition", ProjectUtilities.canUseFileName(p1, null, "foo", "java", false, false));
    assertNull("normal file addition with no extension is OK", ProjectUtilities.canUseFileName(p1, null, "foo", null, false, false));
    assertNull("normal file addition in an existing subdir", ProjectUtilities.canUseFileName(d, "project1", "foo", "java", false, false));
    assertNull("normal file addition in a new subdir", ProjectUtilities.canUseFileName(d, "dir", "foo", "java", false, false));
    //assertNotNull("no target name", ProjectUtilities.canUseFileName(d, "dir", null, "java"));
    assertNotNull("no target folder", ProjectUtilities.canUseFileName(null, "dir", "foo", "java", false, false));
    assertNotNull("file already exists", ProjectUtilities.canUseFileName(p1, null, "f1_1", "java", false, false));
    assertNotNull("file already exists in subdir", ProjectUtilities.canUseFileName(d, "project1", "f1_1", "java", false, false));
    assertNull("similar file already exists in subdir", ProjectUtilities.canUseFileName(d, "project1", "f1_1", "properties", false, false));
    assertNull("similar file already exists in subdir", ProjectUtilities.canUseFileName(d, "project1", "f1_1", null, false, false));
    d = new XMLFileSystem().getRoot();
    assertNotNull("FS is r/o", ProjectUtilities.canUseFileName(d, null, "foo", "java", false, false));
    // #59876: deal with non-disk-based filesystems sensibly
    d = FileUtil.createMemoryFileSystem().getRoot();
    d.createData("bar.java");
    FileUtil.createData(d, "sub/dir/foo.java");
    assertNull("can create file in non-disk FS", ProjectUtilities.canUseFileName(d, null, "foo", "java", false, false));
    assertNotNull("file already exists", ProjectUtilities.canUseFileName(d, null, "bar", "java", false, false));
    assertNotNull("file already exists in subsubdir", ProjectUtilities.canUseFileName(d, "sub/dir", "foo", "java", false, false));
    assertNull("can otherwise create file in subsubdir", ProjectUtilities.canUseFileName(d, "sub/dir", "bar", "java", false, false));
    //#66792: allow to create whole directory tree at once using Folder Template:
    assertNull("can create directory subtree", ProjectUtilities.canUseFileName(d, null, "a/b/c", null, true, false));
    //#59654: do not allow slash and backslash for common templates:
    assertNotNull("cannot create file with slashes", ProjectUtilities.canUseFileName(d, null, "a/b/c", "txt", false, false));
    assertNotNull("cannot create file with backslashes", ProjectUtilities.canUseFileName(d, null, "a\\b\\c", "txt", false, false));
    // Check freeFileExtension mode:
    assertNull(ProjectUtilities.canUseFileName(d, null, "foo", "java", false, true));
    assertNotNull(ProjectUtilities.canUseFileName(d, null, "bar", "java", false, true));
    assertNotNull(ProjectUtilities.canUseFileName(d, null, "bar.java", "java", false, true));
    assertNull(ProjectUtilities.canUseFileName(d, null, "bar.java", "java", false, false));
    String err = ProjectUtilities.canUseFileName(d, null, "<a href='whatever'>HTML\njunk!</a>", "html", false, false);
    assertNotNull(err);
    assertTrue(err, err.contains("&lt;a href='whatever'>HTML junk!&lt;…"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:ProjectUtilitiesTest.java

示例10: storeCustomCommand

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Store custom command to System Filesystem.
 *
 * @param customCommand Command to store.
 */
private void storeCustomCommand(String customCommand) throws IOException {
    FileObject root = FileUtil.getConfigRoot();
    FileObject folder = root.getFileObject(DATA_FOLDER);
    if (folder == null) {
        folder = root.createFolder(DATA_FOLDER);
    }
    FileObject data = folder.getFileObject(DATA_FILE);
    if (data == null) {
        data = folder.createData(DATA_FILE);
    }
    data.setAttribute(CMD_ATTR, customCommand);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:PDFOpenSupport.java

示例11: getProjectCatalogFileObject

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public static FileObject getProjectCatalogFileObject(Project prj, boolean create) throws IOException {
    if(prj == null)
        return null;
    
    FileObject result = null;
    FileObject myProjectRootFileObject = prj.getProjectDirectory();
    
    //see if this prj has XMLCatalogProvider. If yes use it.
    XMLCatalogProvider catProv =  prj.getLookup().lookup(org.netbeans.modules.xml.retriever.XMLCatalogProvider.class);
    if(catProv != null){
        URI caturi = catProv.getProjectWideCatalog();
        if(caturi != null){
            caturi = FileUtil.toFile(myProjectRootFileObject).toURI().resolve(caturi);
            File catFile = new File(caturi);
            if(!catFile.isFile()){
                catFile.createNewFile();
            }
            result = FileUtil.toFileObject(FileUtil.normalizeFile(catFile));
        }
    }
    
    if(result == null){
        String fileName = CatalogWriteModel.PUBLIC_CATALOG_FILE_NAME+CatalogWriteModel.CATALOG_FILE_EXTENSION;
        result = myProjectRootFileObject.getFileObject(fileName);
        if(result == null && create){
            result = myProjectRootFileObject.createData(fileName);
        }
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:Util.java

示例12: getServerListFile

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
protected FileObject getServerListFile() throws IOException {
    FileObject root = Repository.getDefault().getDefaultFileSystem().getRoot();
    FileObject folder = root.getFileObject(serverType);
    if (folder == null) {
        folder = root.createFolder(serverType);
    }

    FileObject serversFile = folder.getFileObject(serversListFileName);
    if (serversFile == null) {
        serversFile = folder.createData(serversListFileName);
    }

    return serversFile;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:15,代码来源:DefaultServersManager.java

示例13: testAddedFile

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testAddedFile() throws Exception {
    FileObject folder = FileUtil.getConfigFile( "foo" );
    FileObject newFile = folder.createData( "newFile", "ext" );
    
    File writableFile = new File( new File( configDir, "foo"), "newFile.ext" );
    assertTrue( writableFile.exists() );

    assertTrue(newFile.canRevert());
    newFile.revert();
    
    assertFalse( "local file removed", writableFile.exists() );
    assertNull( "FileObject does not exist", FileUtil.getConfigFile( "foo/newFile.ext" ) );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:RemoveWritablesTest.java

示例14: createFile

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
protected File createFile(String name) throws IOException {
    FileObject wd = FileUtil.toFileObject(getWorkTreeDir());
    FileObject fo = wd.createData(name);
    return FileUtil.toFile(fo);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:AbstractHgTestCase.java

示例15: testGetResource

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Tests ClassPath.findAllResources(), ClassPath.findResoruce(), 
 * ClassPath.contains (), ClassPath.findOwnerRoot(),
 * ClassPath.isResourceVisible ()
 */
public void testGetResource () throws Exception {
    File root_1 = new File (getBaseDir(),"root_1");
    root_1.mkdir();
    File root_2 = new File (getBaseDir(),"root_2");
    root_2.mkdir();
    FileObject[] roots = new FileObject [] {
        FileUtil.toFileObject(root_1),
        FileUtil.toFileObject(root_2),
    };
    
    FileObject tmp = roots[0].createFolder("org");
    tmp = tmp.createFolder("me");
    FileObject testFo_1 = tmp.createData("Foo","txt");
    tmp = roots[1].createFolder("org");
    tmp = tmp.createFolder("me");
    FileObject testFo_2 = tmp.createData("Foo","txt");        
    ClassPath cp = ClassPathSupport.createClassPath(roots);        
    
    //findResource
    assertTrue(cp.findResource ("org/me/Foo.txt")==testFo_1);
    assertTrue (cp.findResource("org/me/None.txt")==null);
    
    //findAllResources
    List res = cp.findAllResources ("org/me/Foo.txt");
    assertTrue (res.size() == 2);
    assertTrue (res.contains(testFo_1));
    assertTrue (res.contains(testFo_2));
    
    //contains
    assertTrue (cp.contains (testFo_1));
    assertTrue (cp.contains (testFo_2));
    assertFalse (cp.contains (roots[0].getParent()));
    
    //findOwnerRoot
    assertTrue (cp.findOwnerRoot(testFo_1)==roots[0]);
    assertTrue (cp.findOwnerRoot(testFo_2)==roots[1]);

    /*
    //isResourceVisible
    assertTrue (cp.isResourceVisible(testFo_1));
    assertFalse (cp.isResourceVisible(testFo_2));
     */
    
    cp = null;
    roots[0].delete();
    roots[1].delete();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:ClassPathTest.java


注:本文中的org.openide.filesystems.FileObject.createData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。