Example usage for java.net URL getFile

List of usage examples for java.net URL getFile

Introduction

In this page you can find the example usage for java.net URL getFile.

Prototype

public String getFile() 

Source Link

Document

Gets the file name of this URL .

Usage

From source file:com.liferay.httpservice.internal.http.DefaultHttpContextTest.java

protected void getResourceAndVerify(String path) {
    URL url = _defaultHttpContext.getResource(path);

    Assert.assertNotNull(url);//w ww .ja v a  2s. co  m
    Assert.assertEquals(_FILE, url.getFile());
    Assert.assertEquals(_HOST, url.getHost());
    Assert.assertEquals(_PROTOCOL, url.getProtocol());
}

From source file:com.navercorp.pinpoint.bootstrap.java9.module.JarFileAnalyzerTest.java

@Test
public void jarFileToURI() throws IOException {
    URL url = CodeSourceUtils.getCodeLocation(Logger.class);
    logger.debug("url:{}", url);

    JarFile jarFile = new JarFile(url.getFile());
    logger.debug("jarFile:{}", jarFile.getName());
    File file = new File(jarFile.getName());
    logger.debug("url1:{}", file.toURI());
}

From source file:eu.impact_project.iif.t2.client.HelperTest.java

/**
 * Test of parseRequest method, of class Helper.
 *///from w  w  w.  j a  va2  s.  c om
@Test
public void testParseRequest() throws Exception {
    HttpServletRequest request = mock(HttpServletRequest.class);
    URL url = this.getClass().getResource("/prueba.txt");
    File testFile = new File(url.getFile());
    Part[] parts = new Part[] { new StringPart("user", "user"), new FilePart("file_workflow", testFile),
            new FilePart("comon_file", testFile) };

    MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts,
            new PostMethod().getParams());

    ByteArrayOutputStream requestContent = new ByteArrayOutputStream();

    multipartRequestEntity.writeRequest(requestContent);

    final ByteArrayInputStream inputContent = new ByteArrayInputStream(requestContent.toByteArray());

    when(request.getInputStream()).thenReturn(new ServletInputStream() {
        @Override
        public int read() throws IOException {
            return inputContent.read();
        }
    });

    when(request.getContentType()).thenReturn(multipartRequestEntity.getContentType());

    Helper.parseRequest(request);

}

From source file:com.fengduo.bee.commons.core.utilities.ClassPathScanner.java

public List<Class<?>> scan() {
    List<Class<?>> list = new ArrayList<Class<?>>();
    Enumeration<URL> en = null;
    try {/*  w  w w.ja  v  a 2s  .  com*/
        en = getClass().getClassLoader().getResources(dotToPath(packageName));
    } catch (IOException e) {
        e.printStackTrace();
    }
    while (en.hasMoreElements()) {
        URL url = en.nextElement();
        if (PROTOCOL_FILE.equals(url.getProtocol())) {
            File root = new File(url.getFile());
            findInDirectory(list, root, root, packageName);
        } else if (PROTOCOL_JAR.equals(url.getProtocol())) {
            findInJar(list, getJarFile(url), packageName);
        }
    }
    return list;
}

From source file:org.solmix.runtime.support.spring.ContainerXmlBeanDefinitionReader.java

@Override
protected int doLoadBeanDefinitions(InputSource inputSource, Resource resource)
        throws BeanDefinitionStoreException {
    // sadly, the Spring class we are extending has the critical function
    // getValidationModeForResource
    // marked private instead of protected, so trickery is called for here.
    boolean suppressValidation = false;
    try {//from   w ww .  ja  va2  s  .  c  o  m
        URL url = resource.getURL();
        if (url.getFile().contains("META-INF/solmix/")) {
            suppressValidation = true;
        }
    } catch (IOException e) {
        // this space intentionally left blank.
    }

    int savedValidation = visibleValidationMode;
    if (suppressValidation) {
        setValidationMode(VALIDATION_NONE);
    }
    int r = super.doLoadBeanDefinitions(inputSource, resource);
    setValidationMode(savedValidation);
    return r;
}

From source file:fr.eolya.utils.http.HttpUtils.java

/**
 * Encode url//w w w.  j ava  2 s  .c  o  m
 * 
 * @param url url to be encoded
 * @return 
 */
public static String urlEncode(String url) {
    try {
        URL u = new URL(url);
        String host = u.getHost();
        int indexFile = url.indexOf("/", url.indexOf(host));
        if (indexFile == -1)
            return url;

        String urlFile = u.getFile();
        urlFile = URLDecoder.decode(urlFile, "UTF-8");

        String protocol = u.getProtocol();
        int port = u.getPort();
        if (port != -1 && port != 80 && "http".equals(protocol))
            host += ":".concat(String.valueOf(port));
        if (port != -1 && port != 443 && "https".equals(protocol))
            host += ":".concat(String.valueOf(port));

        URI uri = new URI(u.getProtocol(), host, urlFile, null);
        String ret = uri.toASCIIString();
        ret = ret.replaceAll("%3F", "?");
        return ret;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}

From source file:io.dockstore.client.cli.CWLClientTest.java

@Test
public void parseCWL() throws Exception {
    final URL resource = Resources.getResource("cwl.json");
    final CWL cwl = new CWL();
    final ImmutablePair<String, String> output = cwl.parseCWL(resource.getFile(), true);
    assertTrue(!output.getLeft().isEmpty() && output.getLeft().contains("cwlVersion"));
    assertTrue(!output.getRight().isEmpty() && output.getRight().contains("cwltool"));
}

From source file:io.dockstore.client.cli.CWLClientTest.java

@Test
public void extractCWLTypes() throws Exception {
    final URL resource = Resources.getResource("cwl.json");
    final CWL cwl = new CWL();
    final ImmutablePair<String, String> output = cwl.parseCWL(resource.getFile(), true);
    final Map<String, String> typeMap = cwl.extractCWLTypes(output.getLeft());
    assertTrue(typeMap.size() == 3);/*w ww  .  ja va 2 s .  co  m*/
    assertTrue("int".equals(typeMap.get("mem_gb")));
    assertTrue("File".equals(typeMap.get("bam_input")));
}

From source file:com.liferay.ide.alloy.core.webresources.PortalResourcesProvider.java

private File[] createLayoutHelperFiles(String path) throws IOException {
    final URL url = FileLocator.toFileURL(AlloyCore.getDefault().getBundle().getEntry(path));

    return new File[] { new File(url.getFile()) };
}

From source file:eu.delving.sip.TestCoordinateConversion.java

@Before
public void prep() throws IOException {
    URL input = getClass().getResource("/geo/TestCoordinateConversion.txt");
    inputLines = FileUtils.readLines(new File(input.getFile()));
    URL func = getClass().getResource("/geo/TestCoordinateConversion.xml");
    MappingFunction mappingFunction = (MappingFunction) getStream().fromXML(new File(func.getFile()));
    Map<String, String> facts = new TreeMap<String, String>();
    functionScript = groovyCodeResource.createFunctionScript(mappingFunction, facts, null);
}