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