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


Java URL.getFile方法代碼示例

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


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

示例1: list

import java.net.URL; //導入方法依賴的package包/類
private static List<String> list(final String folder,
                                 final String extension,
                                 final boolean isDirectory) {
    final URL url = IO.getURL(folder);
    final List<String> retList = new ArrayList<>();
    if (null != url) {
        final File file = new File(url.getFile());
        if (file.isDirectory() && file.exists()) {
            final File[] files = (isDirectory) ?
                    file.listFiles(File::isDirectory) :
                    (null == extension ?
                            file.listFiles(File::isFile) :
                            file.listFiles((item) -> item.isFile()
                                    && item.getName().endsWith(extension)));
            if (null != files) {
                retList.addAll(Arrays.stream(files)
                        .map(File::getName)
                        .collect(Collectors.toList()));
            }
        }
    }
    return retList;
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:24,代碼來源:Folder.java

示例2: oldDecode

import java.net.URL; //導入方法依賴的package包/類
private static FileObject oldDecode(URL u) {
    String resourceName = u.getFile();

    if (resourceName.startsWith("/")) {
        resourceName = resourceName.substring(1); // NOI18N
    }

    // first part is FS name
    int first = resourceName.indexOf('/'); // NOI18N

    if (first == -1) {
        return null;
    }

    String fileSystemName = oldDecodeFSName(resourceName.substring(0, first));
    resourceName = resourceName.substring(first);

    FileSystem fsys = Repository.getDefault().findFileSystem(fileSystemName);

    return (fsys == null) ? null : fsys.findResource(resourceName);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:NbfsUtil.java

示例3: readRecordsDirectly

import java.net.URL; //導入方法依賴的package包/類
public String[] readRecordsDirectly(URL testFileUrl, boolean bzip)
    throws IOException {
  int MAX_DATA_SIZE = 1024 * 1024;
  byte[] data = new byte[MAX_DATA_SIZE];
  FileInputStream fis = new FileInputStream(testFileUrl.getFile());
  int count;
  if (bzip) {
    BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(fis);
    count = bzIn.read(data);
    bzIn.close();
  } else {
    count = fis.read(data);
  }
  fis.close();
  assertTrue("Test file data too big for buffer", count < data.length);
  return new String(data, 0, count, "UTF-8").split("\n");
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestLineRecordReader.java

示例4: getPathFromUrl

import java.net.URL; //導入方法依賴的package包/類
public static String getPathFromUrl(URL file)
{
	if( !file.getProtocol().equals("file") )
	{
		throw new Error("Must be a file: url! - " + file);
	}
	try
	{
		String part = file.getFile();
		String os = System.getProperty("os.name").toLowerCase();
		if( os.indexOf("windows") >= 0 && part.startsWith("/") )
		{
			part = part.substring(1);
			part = part.replaceAll("/", Matcher.quoteReplacement("\\"));
		}

		return URLDecoder.decode(part.replace("+", "%2b"), "UTF-8");
	}
	catch( UnsupportedEncodingException e )
	{
		throw new RuntimeException(e);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:24,代碼來源:AbstractTest.java

示例5: getResource

import java.net.URL; //導入方法依賴的package包/類
/**
 * Get resource path, supporting file and url io path
 * 
 * @return path to the file
 */
public static String getResource(String filePath) {
	if (FileIO.exist(filePath))
		return filePath;

	String path = makeDirPath(new String[] { "src", "main", "resources" }) + filePath;
	if (FileIO.exist(path))
		return path;

	URL is = Class.class.getResource(filePath);
	if (is != null)
		return is.getFile();

	is = Class.class.getResource(path);
	if (is != null)
		return is.getFile();

	return null;
}
 
開發者ID:xiaojieliu7,項目名稱:MicroServiceProject,代碼行數:24,代碼來源:FileIO.java

示例6: classPathEntryFromURL

import java.net.URL; //導入方法依賴的package包/類
private String classPathEntryFromURL(Class cls) {
    String shortName = cls.getName().substring(1+cls.getName().lastIndexOf('.'));
    URL url = cls.getResource(shortName + ".class");
    String file = url.getFile();
    if (url.getProtocol().equals("jar")) {
        // example: file = 'jar:/usr/local/j2sdkee1.3.1/lib/j2ee.jar!/org/w3c/dom/Node.class'
        String jarFile = file.substring(file.indexOf(':')+1);
        jarFile = jarFile.substring(0, jarFile.indexOf('!'));
        return jarFile;
    } else if (url.getProtocol().equals("file")) {
        // example: file='/home/cliffwd/cvs/dublin/nb_all/schema2beans/rt/src/org/netbeans/modules/schema2beans/GenBeans.class'
        String result = file.substring(0, file.length() - cls.getName().length() - 6);
        return result;
    } else {
        return file;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:MainTest.java

示例7: runClasspathFeature

import java.net.URL; //導入方法依賴的package包/類
public static Map<String, Object> runClasspathFeature(String classPath, Map<String, Object> vars, boolean evalKarateConfig) {
    URL url = Thread.currentThread().getContextClassLoader().getResource(classPath);
    if (url == null) {
        throw new RuntimeException("file not found: " + classPath);
    }
    File file = new File(url.getFile());
    return runFeature(file, vars, evalKarateConfig);
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:9,代碼來源:CucumberRunner.java

示例8: should_remove_sync_task_if_create_session_failure_on_callback

import java.net.URL; //導入方法依賴的package包/類
@Test
public void should_remove_sync_task_if_create_session_failure_on_callback() throws Throwable {
    // given: copy exist git to workspace
    ClassLoader classLoader = TestBase.class.getClassLoader();
    URL resource = classLoader.getResource("hello.git");
    File path = new File(resource.getFile());
    FileUtils.copyDirectoryToDirectory(path, gitWorkspace.toFile());

    // and: register agent to sync service
    AgentPath agent = agents.get(0);
    syncService.register(agent);

    // when: execute sync task
    syncService.syncTask();

    // then: the create session cmd should be send
    CountMatchingStrategy strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 1);
    verify(strategy, postRequestedFor(urlEqualTo("/cmd/queue/send?priority=10&retry=5")));

    // when: mock create session failure
    Cmd mockSessionCallback = new Cmd(agent.getZone(), agent.getName(), CmdType.CREATE_SESSION, null);
    mockSessionCallback.setStatus(CmdStatus.EXCEPTION);
    mockSessionCallback.setSessionId(createSessionCmdResponse.getSessionId());
    syncService.onCallback(mockSessionCallback);

    // then: sync task for agent should be removed
    Assert.assertNull(syncService.getSyncTask(agent));
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:29,代碼來源:SyncServiceTest.java

示例9: createItemsPanel

import java.net.URL; //導入方法依賴的package包/類
/**
 * @param centerPanel
 * @param urlList
 */
private static void createItemsPanel(JPanel centerPanel, List<URL> urlList)
{
	JPanel itemsPanel = new JPanel();
	centerPanel.add(itemsPanel, BorderLayout.CENTER);
	
	if(CollectionUtils.isEmpty(urlList))
	{
		return;
	}
	
	for(URL url : urlList)
	{
		String text = url.getFile();
		JCheckBox box = new JCheckBox(new File(text).getName());
		box.addActionListener(new ActionListener()
		{
			
			@Override
			public void actionPerformed(ActionEvent e)
			{
				JCheckBox source = (JCheckBox) e.getSource();
				if(source.isSelected())
				{
					runnerList.add(source.getText());
				}
				else
				{
					runnerList.remove(source.getText());
				}
			}
		});
		
		itemsPanel.add(box);
	}
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.suite.runner,代碼行數:40,代碼來源:SuiteRunnerLauncher.java

示例10: should_save_and_get_yml_success

import java.net.URL; //導入方法依賴的package包/類
@Test
public void should_save_and_get_yml_success() throws IOException {
    Job job = new Job(CommonUtil.randomId());
    ClassLoader classLoader = JobYmlDaoTest.class.getClassLoader();
    URL resource = classLoader.getResource("yml/flow.yaml");
    File path = new File(resource.getFile());
    String ymlString = Files.toString(path, AppConfig.DEFAULT_CHARSET);
    JobYml jys = new JobYml(job.getId(), ymlString);
    jobYmlDao.save(jys);
    JobYml storage = jobYmlDao.get(jys.getJobId());
    Assert.assertNotNull(storage);
    Assert.assertEquals(ymlString, storage.getFile());
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:14,代碼來源:JobYmlDaoTest.java

示例11: setup

import java.net.URL; //導入方法依賴的package包/類
@Before
public void setup() throws Exception {
    URL sourceUrl = this.getClass().getResource("/");

    sourceFolder = new File(sourceUrl.getFile());
    if (!sourceFolder.exists()) {
        throw new Exception("Cannot find sample data structure!");
    }

    config = ConfigUtil.load(new File(this.getClass().getResource("/").getFile()));
    Assert.assertEquals(".html", config.getString(Keys.OUTPUT_EXTENSION));
    db = DBUtil.createDataStore("memory", "documents" + System.currentTimeMillis());
}
 
開發者ID:ghaseminya,項目名稱:jbake-rtl-jalaali,代碼行數:14,代碼來源:CrawlerTest.java

示例12: JarLoader

import java.net.URL; //導入方法依賴的package包/類
JarLoader(URL url, URLStreamHandler jarHandler,
          HashMap<String, Loader> loaderMap,
          AccessControlContext acc)
    throws IOException
{
    super(new URL("jar", "", -1, url + "!/", jarHandler));
    csu = url;
    handler = jarHandler;
    lmap = loaderMap;
    this.acc = acc;

    if (!isOptimizable(url)) {
        ensureOpen();
    } else {
         String fileName = url.getFile();
        if (fileName != null) {
            fileName = ParseUtil.decode(fileName);
            File f = new File(fileName);
            metaIndex = MetaIndex.forJar(f);
            // If the meta index is found but the file is not
            // installed, set metaIndex to null. A typical
            // senario is charsets.jar which won't be installed
            // when the user is running in certain locale environment.
            // The side effect of null metaIndex will cause
            // ensureOpen get called so that IOException is thrown.
            if (metaIndex != null && !f.exists()) {
                metaIndex = null;
            }
        }

        // metaIndex is null when either there is no such jar file
        // entry recorded in meta-index file or such jar file is
        // missing in JRE. See bug 6340399.
        if (metaIndex == null) {
            ensureOpen();
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:39,代碼來源:URLClassPath.java

示例13: getCPFile

import java.net.URL; //導入方法依賴的package包/類
public static String getCPFile(String path) {
    URL url = FileUtil.class.getClassLoader().getResource(path);
    String filepath = url.getFile();
    File file = new File(filepath);
    byte[] retBuffer = new byte[(int) file.length()];
    try {
        FileInputStream fis = new FileInputStream(filepath);
        fis.read(retBuffer);
        fis.close();
        return new String(retBuffer, "GBK");
    } catch (IOException e) {
        //Debug.error("FileUtils.getCPFile讀取文件異常:" + e.toString());
        return null;
    }
}
 
開發者ID:xm0625,項目名稱:VBrowser-Android,代碼行數:16,代碼來源:FileUtil.java

示例14: stubDemo

import java.net.URL; //導入方法依賴的package包/類
public void stubDemo() {
    Cmd mockCmdResponse = new Cmd();
    mockCmdResponse.setId(UUID.randomUUID().toString());
    mockCmdResponse.setSessionId(UUID.randomUUID().toString());

    stubFor(post(urlEqualTo("/cmd/queue/send?priority=1&retry=5"))
        .willReturn(aResponse()
            .withBody(mockCmdResponse.toJson())));

    stubFor(post(urlEqualTo("/cmd/send"))
        .willReturn(aResponse()
            .withBody(mockCmdResponse.toJson())));

    stubFor(post(urlEqualTo("/cmd/stop/" + mockCmdResponse.getId()))
        .willReturn(aResponse()
            .withBody(mockCmdResponse.toJson())));

    ClassLoader classLoader = TestBase.class.getClassLoader();
    URL resource = classLoader.getResource("step_log.zip");
    File path = new File(resource.getFile());

    try (InputStream inputStream = new FileInputStream(path)) {
        stubFor(
            get(urlPathEqualTo("/cmd/log/download"))
            .willReturn(aResponse().withBody(org.apache.commons.io.IOUtils.toByteArray(inputStream))));
    } catch (Throwable throwable) {
    }
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:29,代碼來源:TestBase.java

示例15: getFileByURL

import java.net.URL; //導入方法依賴的package包/類
private static File getFileByURL(URL fileUrl) throws FileNotFoundException {
	Validate.notNull(fileUrl, "Resource URL must not be null");
	if (!URL_PROTOCOL_FILE.equals(fileUrl.getProtocol())) {
		throw new FileNotFoundException("URL cannot be resolved to absolute file path "
				+ "because it does not reside in the file system: " + fileUrl);
	}
	try {
		return new File(toURI(fileUrl.toString()).getSchemeSpecificPart());
	} catch (URISyntaxException ex) {
		// Fallback for URLs that are not valid URIs (should hardly ever
		// happen).
		return new File(fileUrl.getFile());
	}
}
 
開發者ID:zhangjunfang,項目名稱:util,代碼行數:15,代碼來源:URLResourceUtil.java


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