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


Java Utilities.toFile方法代碼示例

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


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

示例1: findForCPExt

import org.openide.util.Utilities; //導入方法依賴的package包/類
/**
 * Find Javadoc roots for classpath extensions ("wrapped" JARs) of the project
 * added by naming convention <tt>&lt;jar name&gt;-javadoc(.zip)</tt>
 * See issue #66275
 * @param binaryRoot
 * @return
 */
private Result findForCPExt(URL binaryRoot) {
    URL jar = FileUtil.getArchiveFile(binaryRoot);
    if (jar == null)
        return null;    // not a class-path-extension
    File binaryRootF = Utilities.toFile(URI.create(jar.toExternalForm()));
    // XXX this will only work for modules following regular naming conventions:
    String n = binaryRootF.getName();
    if (!n.endsWith(".jar")) { // NOI18N
        // ignore
        return null;
    }
    // convention-over-cfg per mkleint's suggestion: <jarname>-javadoc(.zip) folder or ZIP
    File jFolder = new File(binaryRootF.getParentFile(), 
            n.substring(0, n.length() - ".jar".length()) + "-javadoc");
    if (jFolder.isDirectory()) {
            return new R(new URL[]{FileUtil.urlForArchiveOrDir(jFolder)});
    } else {
        File jZip = new File(jFolder.getAbsolutePath() + ".zip");
        if (jZip.isFile()) {
            return new R(new URL[]{FileUtil.urlForArchiveOrDir(jZip)});
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:JavadocForBinaryImpl.java

示例2: testBrokenShadow55115

import org.openide.util.Utilities; //導入方法依賴的package包/類
public void testBrokenShadow55115 () throws Exception {
    FileObject brokenShadow = FileUtil.createData(FileUtil.getConfigRoot(),"brokenshadows/brokon.shadow");
    assertNotNull (brokenShadow);
    // intentionally not set attribute "originalFile" to let that shadow be broken 
    //brokenShadow.setAttribute("originalFile", null);
    BrokenDataShadow bds = (BrokenDataShadow)DataObject.find(brokenShadow);
    assertNotNull (bds);
    URL url = bds.getUrl();
    //this call proves #55115 - but just in case if there is reachable masterfs 
    // - probably unwanted here
    bds.refresh(); 
    
    //If masterfs isn't reachable - second test crucial for URL,File, FileObject conversions
    // not necessary to be able to convert - but at least no IllegalArgumentException is expected
    if ("file".equals(url.getProtocol())) {
        Utilities.toFile(URI.create(url.toExternalForm()));
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:DataShadowTest.java

示例3: addWatchedPath

import org.openide.util.Utilities; //導入方法依賴的package包/類
/**
 * 
 * @param uri
 */
public void addWatchedPath(URI uri) {
    //#110599
    boolean addListener = false;
    File fil = Utilities.toFile(uri);
    synchronized (files) {
//#216001 addWatchedPath appeared to accumulate files forever on each project reload.
//that's because source roots get added repeatedly but never get removed and listening to changed happens elsewhere.
//the imagined fix for 216001 is to keep each item just once. That would break once multiple sources add a given file and one of them removes it
//as a hotfix this solution is ok, if we don't get some data updated, we should remove the watchedPath pattern altogether.
        if (files.add(fil)) {
            addListener = true;
        }
    }
    if (addListener) {
        FileUtil.addFileChangeListener(listener, fil);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:NbMavenProject.java

示例4: keys

import org.openide.util.Utilities; //導入方法依賴的package包/類
public List<String> keys() {
    List<String> result = new ArrayList<String>();
    result.add(LIBRARIES);
    URL[] testRoots = project.getTestSourceRoots().getRootURLs();
    boolean addTestSources = false;
    for (int i = 0; i < testRoots.length; i++) {
        File f = Utilities.toFile(URI.create(testRoots[i].toExternalForm()));
        if (f.exists()) {
            addTestSources = true;
            break;
        }
    }
    if (addTestSources) {
        result.add(TEST_LIBRARIES);
    }
    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:LibrariesNodeFactory.java

示例5: createModel

import org.openide.util.Utilities; //導入方法依賴的package包/類
public static DefaultTableModel createModel( ModuleRoots roots ) {
    
    URL[] rootURLs = roots.getRootURLs(false);
    String[] rootPaths = roots.getRootPathProperties();
    Object[][] data = new Object[rootURLs.length] [2];
    for (int i = 0; i < rootURLs.length; i++) {
        data[i][0] = Utilities.toFile(URI.create (rootURLs[i].toExternalForm()));
        data[i][1] = roots.getRootPath(rootPaths[i]);
    }
    return new SourceRootsModel(data);
 
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:SourceRootsUi.java

示例6: getOrCreateFolder

import org.openide.util.Utilities; //導入方法依賴的package包/類
/**
 * creates or finds FileObject according to
 *
 * @param url
 * @return FileObject
 */
private FileObject getOrCreateFolder(URL url) throws IOException {
    try {
        FileObject result = URLMapper.findFileObject(url);
        if (result != null) {
            return result;
        }
        File f = Utilities.toFile(url.toURI());

        result = FileUtil.createFolder(f);
        return result;
    } catch (URISyntaxException ex) {
        throw new IOException(ex);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:MoveClassTransformer.java

示例7: run

import org.openide.util.Utilities; //導入方法依賴的package包/類
private void run(File workDir, String... args) throws Exception {
    URL u = Lookup.class.getProtectionDomain().getCodeSource().getLocation();
    File f = Utilities.toFile(u.toURI());
    assertTrue("file found: " + f, f.exists());
    File nbexec = Utilities.isWindows() ? new File(f.getParent(), "nbexec.exe") : new File(f.getParent(), "nbexec");
    assertTrue("nbexec found: " + nbexec, nbexec.exists());

    URL tu = MainCallback.class.getProtectionDomain().getCodeSource().getLocation();
    File testf = Utilities.toFile(tu.toURI());
    assertTrue("file found: " + testf, testf.exists());
    
    LinkedList<String> allArgs = new LinkedList<String>(Arrays.asList(args));
    allArgs.addFirst("-J-Dnetbeans.mainclass=" + MainCallback.class.getName());
    allArgs.addFirst(System.getProperty("java.home"));
    allArgs.addFirst("--jdkhome");
    allArgs.addFirst(getWorkDirPath());
    allArgs.addFirst("--userdir");
    allArgs.addFirst(testf.getPath());
    allArgs.addFirst("-cp:p");
    
    if (!Utilities.isWindows()) {
        allArgs.addFirst(nbexec.getPath());
        allArgs.addFirst("-x");
        allArgs.addFirst("/bin/sh");
    } else {
        allArgs.addFirst(nbexec.getPath());
    }
    
    StringBuffer sb = new StringBuffer();
    Process p = Runtime.getRuntime().exec(allArgs.toArray(new String[allArgs.size()]), new String[0], workDir);
    int res = readOutput(sb, p);
    
    String output = sb.toString();
    
    assertEquals("Execution is ok: " + output, 0, res);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:NbExecPassesCorrectlyQuotedArgsTest.java

示例8: save

import org.openide.util.Utilities; //導入方法依賴的package包/類
public void save() {
    synchronized (this) {
        if (lastSave >= modificationCount) return ; //already saved
        lastSave = modificationCount;
    }
    
    File file = Utilities.toFile(settings); //XXX: non-file:// scheme
    try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
        XMLUtil.write(doc, out, "UTF-8");
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:XMLHintPreferences.java

示例9: getAttachementData

import org.openide.util.Utilities; //導入方法依賴的package包/類
@Override
public void getAttachementData (final OutputStream os) {
    try {
        File f = Utilities.toFile(new URI(uri));
        FileUtils.copyStreamsCloseAll(os, FileUtils.createInputStream(f));
    } catch (URISyntaxException | IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:LocalTask.java

示例10: setUp

import org.openide.util.Utilities; //導入方法依賴的package包/類
@Override
protected void setUp() throws Exception {
    super.setUp();
    URL urlToFile = DefaultTestCase.class.getResource ("data/org-yourorghere-depending.nbm");
    NBM_FILE = Utilities.toFile(urlToFile.toURI ());
    assertNotNull ("data/org-yourorghere-depending.nbm file must found.", NBM_FILE);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:AutoupdateInfoParserTest.java

示例11: from

import org.openide.util.Utilities; //導入方法依賴的package包/類
public static HintPreferencesProviderImpl from(@NonNull URI settings) {
    Reference<HintPreferencesProviderImpl> ref = uri2Cache.get(settings);
    HintPreferencesProviderImpl cachedResult = ref != null ? ref.get() : null;
    
    if (cachedResult != null) return cachedResult;
    
    Document doc = null;
    File file = Utilities.toFile(settings); //XXX: non-file:// scheme
    
    if (file.canRead()) {
        try(InputStream in = new BufferedInputStream(new FileInputStream(file))) {
            doc = XMLUtil.parse(new InputSource(in), false, false, null, EntityCatalog.getDefault());
        } catch (SAXException | IOException ex) {
            LOG.log(Level.FINE, null, ex);
        }
    }
    
    if (doc == null) {
        doc = XMLUtil.createDocument("configuration", null, "-//NetBeans//DTD Tool Configuration 1.0//EN", "http://www.netbeans.org/dtds/ToolConfiguration-1_0.dtd");
    }
    
    synchronized (uri2Cache) {
        ref = uri2Cache.get(settings);
        cachedResult = ref != null ? ref.get() : null;

        if (cachedResult != null) return cachedResult;
        
        uri2Cache.put(settings, new CleaneableSoftReference(cachedResult = new HintPreferencesProviderImpl(settings, doc), settings));
    }
    
    return cachedResult;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:33,代碼來源:XMLHintPreferences.java

示例12: invokeNbExecAndCreateCluster

import org.openide.util.Utilities; //導入方法依賴的package包/類
private void invokeNbExecAndCreateCluster(File workDir, StringBuffer sb, String... args) throws Exception {
        URL u = Lookup.class.getProtectionDomain().getCodeSource().getLocation();
        File f = Utilities.toFile(u.toURI());
        assertTrue("file found: " + f, f.exists());
        File nbexec = org.openide.util.Utilities.isWindows() ? new File(f.getParent(), "nbexec.exe") : new File(f.getParent(), "nbexec");
        assertTrue("nbexec found: " + nbexec, nbexec.exists());
        LOG.log(Level.INFO, "nbexec: {0}", nbexec);

        URL tu = NewClustersRebootCallback.class.getProtectionDomain().getCodeSource().getLocation();
        File testf = Utilities.toFile(tu.toURI());
        assertTrue("file found: " + testf, testf.exists());

        LinkedList<String> allArgs = new LinkedList<String>(Arrays.asList(args));
        allArgs.addFirst("-J-Dnetbeans.mainclass=" + NewClustersRebootCallback.class.getName());
        allArgs.addFirst(System.getProperty("java.home"));
        allArgs.addFirst("--jdkhome");
        allArgs.addFirst(getWorkDirPath());
        allArgs.addFirst("--userdir");
        allArgs.addFirst(testf.getPath());
        allArgs.addFirst("-cp:p");
        allArgs.addFirst("--nosplash");

        if (!org.openide.util.Utilities.isWindows()) {
            allArgs.addFirst(nbexec.getPath());
            allArgs.addFirst("-x");
            allArgs.addFirst("/bin/sh");
        } else {
            allArgs.addFirst(nbexec.getPath());
        }
        LOG.log(Level.INFO, "About to execute {0}@{1}", new Object[]{allArgs, workDir});
        Process p = Runtime.getRuntime().exec(allArgs.toArray(new String[0]), new String[0], workDir);
        LOG.log(Level.INFO, "Process created {0}", p);
        int res = readOutput(sb, p);
        LOG.log(Level.INFO, "Output read: {0}", res);
        String output = sb.toString();
//        System.out.println("nbexec output is: " + output);
        assertEquals("Execution is ok: " + output, 0, res);
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:NewClustersRebootTest.java

示例13: isCluster

import org.openide.util.Utilities; //導入方法依賴的package包/類
static boolean isCluster(String name) throws URISyntaxException {
    URL where = NbModuleSuite.class.getProtectionDomain().getCodeSource().getLocation();
    File nbjunitJAR = Utilities.toFile(where.toURI());
    assertTrue(nbjunitJAR.exists());
    File harness = nbjunitJAR.getParentFile().getParentFile();
    assertEquals("harness", harness.getName());
    File root = harness.getParentFile();
    return new File(root, "extide").isDirectory();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:NbModuleSuiteTest.java

示例14: testUsingNbfsProtocol

import org.openide.util.Utilities; //導入方法依賴的package包/類
/** Ensure that a user-mode class can at least use findResource() to access
 * resources in filesystems.
 * @see "#13038"
 */
public void testUsingNbfsProtocol() throws Exception {
    System.setProperty("org.netbeans.core.Plain.CULPRIT", "true");
    File here = Utilities.toFile(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
    assertTrue("Classpath really contains " + here,
            new File(new File(new File(new File(here, "org"), "openide"), "execution"), "NbClassLoaderTest.class").canRead());
    
    File dataDir = new File(new File(new File(new File(here, "org"), "openide"), "execution"), "data");
    if(!dataDir.exists()) {
        dataDir.mkdir();
    }
    File fooFile = new File(dataDir, "foo.xml");
    if(!fooFile.exists()) {
        fooFile.createNewFile();
    }
    
    LocalFileSystem lfs = new LocalFileSystem();
    lfs.setRootDirectory(here);
    lfs.setReadOnly(true);
    ClassLoader cl = new NbClassLoader(new FileObject[] {lfs.getRoot()}, ClassLoader.getSystemClassLoader().getParent(), null);
    System.setSecurityManager(new MySecurityManager());
    // Ensure this class at least has free access:
    System.getProperty("foo");
    Class c = cl.loadClass("org.openide.execution.NbClassLoaderTest$User");
    assertEquals(cl, c.getClassLoader());
    try {
        c.newInstance();
    } catch (ExceptionInInitializerError eiie) {
        Throwable t = eiie.getException();
        if (t instanceof IllegalStateException) {
            fail(t.getMessage());
        } else if (t instanceof Exception) {
            throw (Exception)t;
        } else {
            throw new Exception(t.toString());
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:42,代碼來源:NbClassLoaderTest.java

示例15: isReset

import org.openide.util.Utilities; //導入方法依賴的package包/類
@Override
protected boolean isReset(PropertyChangeEvent evt) {
    boolean reset = false;            
    if( (NbMavenProject.PROP_RESOURCE.equals(evt.getPropertyName()) && evt.getNewValue() instanceof URI)) {
        File file = Utilities.toFile((URI) evt.getNewValue());
        MavenProject mp = proj.getOriginalMavenProject();
        reset = mp.getCompileSourceRoots().stream().anyMatch((sourceRoot) -> (file.equals(new File(sourceRoot, MODULE_INFO_JAVA)))) ||
                mp.getTestCompileSourceRoots().stream().anyMatch((sourceRoot) -> (file.equals(new File(sourceRoot, MODULE_INFO_JAVA))));                
        if(reset) {
            LOGGER.log(Level.FINER, "TestPathSelector {0} for project {1} resource changed: {2}", new Object[]{logDesc, proj.getProjectDirectory().getPath(), evt});
        }
    }
    return reset;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:ClassPathProviderImpl.java


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