本文整理汇总了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;
}
示例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);
}
示例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");
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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));
}
示例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);
}
}
示例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());
}
示例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());
}
示例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();
}
}
}
示例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;
}
}
示例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) {
}
}
示例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());
}
}