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:net.sf.groovyMonkey.actions.CreateGroovyMonkeyExamplesAction.java

public void run(final IAction action) {
    final IWorkspace workspace = getWorkspace();
    final IProject project = workspace.getRoot().getProject(SCRIPTS_PROJECT);
    try {/*  w w  w  .java2  s  . c o m*/
        final List<URL> examples = getExampleScripts(getDefault().getBundle());
        if (!project.exists())
            project.create(null);
        project.open(null);

        String errors = "";
        for (final URL example : examples) {
            try {
                final String filePath = example.getFile();
                final String[] words = filePath.split("/");
                final String fileName = words[words.length - 1];
                final IFolder folder = project.getFolder("/" + MONKEY_DIR);
                if (!folder.exists())
                    folder.create(IResource.NONE, true, null);
                final InputStream input = example.openStream();
                try {
                    final IFile file = folder.getFile(fileName);
                    final String contents = StringUtils.replace(IOUtils.toString(input), "\r\n", "\n");
                    file.create(new ByteArrayInputStream(contents.getBytes()), false, null);
                } finally {
                    closeQuietly(input);
                }
            } catch (final CoreException x) {
                errors += x.toString() + "\n";
            } catch (final IOException x) {
                errors += x.toString() + "\n";
            }
        }
        if (errors.length() > 0)
            openInformation(window.getShell(), "Groovy Monkey",
                    "Errors creating the Examples project: " + errors);
    } catch (final CoreException x) {
        openInformation(window.getShell(), "Groovy Monkey",
                "Unable to create the Examples project due to " + x);
    }
}

From source file:org.opencredo.cloud.storage.azure.rest.internal.XPathContainerObjectListFactoryTest.java

@Test
public void testCreateContainersList() throws Exception {
    String fileName = getClass().getPackage().getName().replace('.', '/') + "/containerObjectList.xml";
    URL resource = getClass().getClassLoader().getResource(fileName);

    assertNotNull("Unable to find file: " + fileName, resource);
    HttpEntity entity = new FileEntity(new File(resource.getFile()), null);
    List<BlobDetails> containersList = factory.createContainerObjectDetailsList("container1", entity);
    assertEquals("Incorrect amount of container objects", 2, containersList.size());
}

From source file:com.surveypanel.form.InMemoryFormFactory.java

public FileTemplateLoader getTemplateLoader(long surveyId) {
    URL resource = getClass().getResource("/templates/");
    try {// w  w  w  .  ja v  a  2 s . c om
        return new FileTemplateLoader(new File(resource.getFile()));
    } catch (IOException e) {
        logger.error(e);
    }
    return null;
}

From source file:com.wavemaker.tools.ws.WebServiceToolsManager.java

/**
 * Given the systemId which could be of format like "http://www.abc.com/test.xsd" or "file:/C:/temp/test.xsd". If
 * the systemId represents a local XSD file (e.g. file:C:/temp/test.xsd) then returns it; otherwise returns null.
 * /* ww w.  j  ava 2 s .co  m*/
 * @param systemId
 * @return An XSD file.
 */
private static java.io.File getLocalXsdFileFromSystemId(String systemId) {
    if (!systemId.endsWith(Constants.XSD_EXT)) {
        return null;
    }
    URL url = null;
    try {
        url = new URL(systemId);
    } catch (MalformedURLException e) {
        return null;
    }
    if (url.getProtocol().equals("file") && url.getFile() != null) {
        return new java.io.File(url.getFile());
    } else {
        return null;
    }
}

From source file:org.opencredo.cloud.storage.azure.rest.internal.XPathContainerListFactoryTest.java

@Test
public void testCreateContainersList() throws Exception {
    String fileName = getClass().getPackage().getName().replace('.', '/') + "/containerList.xml";
    URL resource = getClass().getClassLoader().getResource(fileName);

    assertNotNull("Unable to find file: " + fileName, resource);
    HttpEntity entity = new FileEntity(new File(resource.getFile()), null);
    List<String> containersList = factory.createContainerNamesList(entity);
    assertEquals("Incorrect amount of containers", 3, containersList.size());
    for (String containerName : containersList) {
        System.out.println("Container: " + containerName);
    }/*ww w . j  av  a 2s  .c om*/
}

From source file:hudson.plugins.testlink.result.parser.tap.TestTapParser.java

public void testTapParser() {
    assertEquals(this.parser.getName(), "TAP");

    ClassLoader cl = TestTapParser.class.getClassLoader();
    URL url = cl.getResource("hudson/plugins/testlink/result/parser/tap/br.eti.kinoshita.tap.SampleTest.tap");
    File file = new File(url.getFile());

    TestSet testSet = null;//from  w ww  . j  a va 2s.com

    try {
        testSet = this.parser.parse(file);
    } catch (ParserException pe) {
        fail("Failed to parse TAP file '" + file + "': " + pe.getMessage());
    }

    assertNotNull("Failed to parse TAP. Null TestSet.", testSet);
    assertTrue("Wrong number of test results in TAP file '" + file + "'.",
            testSet.getNumberOfTestResults() == 1);
    assertTrue("Wrong status for test result 1", testSet.getTestResult(1).getStatus() == StatusValues.OK);
    assertTrue(testSet.getTestResult(1).getDescription().equals("testOk"));
}

From source file:com.digitalpebble.stormcrawler.protocol.file.FileResponse.java

public FileResponse(String u, Metadata md, FileProtocol fp) throws MalformedURLException, IOException {

    fileProtocol = fp;//from   w ww . ja  v a 2 s. c o m
    metadata = md;

    URL url = new URL(u);

    if (!url.getPath().equals(url.getFile())) {
        LOG.warn("url.getPath() != url.getFile(): {}.", url);
    }

    String path = "".equals(url.getPath()) ? "/" : url.getPath();

    File file = new File(URLDecoder.decode(path, fileProtocol.getEncoding()));

    if (!file.exists()) {
        statusCode = HttpStatus.SC_NOT_FOUND;
        return;
    }

    if (!file.canRead()) {
        statusCode = HttpStatus.SC_UNAUTHORIZED;
        return;
    }

    if (!file.equals(file.getCanonicalFile())) {
        metadata.setValue(HttpHeaders.LOCATION, file.getCanonicalFile().toURI().toURL().toString());
        statusCode = HttpStatus.SC_MULTIPLE_CHOICES;
        return;
    }

    if (file.isDirectory()) {
        getDirAsHttpResponse(file);
    } else if (file.isFile()) {
        getFileAsHttpResponse(file);
    } else {
        statusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        return;
    }

    if (content == null) {
        content = new byte[0];
    }
}

From source file:com.retroduction.carma.resolvers.util.TestCaseInstantiationVerifier.java

private void reinitPrivateClassLoader() {

    Set<File> combinedClassPathSet = new HashSet<File>();

    if (this.getClassPath() != null) {
        combinedClassPathSet.addAll(this.getClassPath());
    }//from   ww w  .ja  v  a2  s .c  o m

    if (this.getTestClassPath() != null) {
        combinedClassPathSet.addAll(this.getTestClassPath());
    }

    if (this.getDependencyClassPath() != null) {

        for (URL url : this.getDependencyClassPath()) {
            File file = new File(url.getFile());
            combinedClassPathSet.add(file);
        }

    }

    Set<URL> validURLs = this.filterInvalidURLs(combinedClassPathSet);

    this.setLoader(new URLClassLoader(validURLs.toArray(new URL[0]), this.getClass().getClassLoader()));
}

From source file:com.revo.deployr.rbroker.example.data.io.anon.discrete.task.EncodedDataInBinaryFileOut.java

public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult) {

    if (rTaskResult.isSuccess()) {

        log.info("[  TASK RESULT   ] Discrete task " + "completed in " + rTaskResult.getTimeOnCall()
                + "ms [ RTaskResult ].");

        /*//from w ww  . jav  a2  s.c  o  m
         * Retrieve the working directory files (artifact)
         * was generated by the execution.
         */
        List<URL> wdFiles = rTaskResult.getGeneratedFiles();

        for (URL wdFile : wdFiles) {
            String fileName = wdFile.getFile();
            if (fileName.endsWith("hip.rData")) {
                log.info("[  DATA OUTPUT   ] Retrieved working " + "directory file output "
                        + fileName.substring(fileName.lastIndexOf("/") + 1) + " [ URL ]");
                InputStream fis = null;
                try {
                    fis = wdFile.openStream();
                    IOUtils.toByteArray(fis);
                } catch (Exception ex) {
                    log.warn("Working directory binary file " + ex);
                } finally {
                    IOUtils.closeQuietly(fis);
                }
            }
        }
    } else {
        log.info("[  TASK RESULT   ] Discrete task " + "failed, cause " + rTaskResult.getFailure());
    }

    /*
     * Unblock main thread so example application can release 
     * resources before exit.
     */
    latch.countDown();
}

From source file:hudson.plugins.testlink.result.ResultSeekerTestCase.java

protected void setUp() throws Exception {
    super.setUp();

    project = createFreeStyleProject();/*from w  ww . ja  v a 2  s. c  o m*/
    File temp = File.createTempFile("resultseeker", Long.toString(System.nanoTime()));

    if (!(temp.delete())) {
        throw new IOException("Could not delete temp directory " + temp);
    }

    if (!(temp.mkdir())) {
        throw new IOException("Could not create temp directory " + temp);
    }

    File workspaceFile = new File(temp, getResultsDirectory());

    if (!(workspaceFile.mkdirs())) {
        throw new IOException("Could not create temp workspace " + temp);
    }

    ClassLoader cl = ResultSeekerTestCase.class.getClassLoader();
    URL url = cl.getResource(getResultsDirectory());
    File junitDir = new File(url.getFile());

    FileUtils.copyDirectory(junitDir, workspaceFile);

    project.setCustomWorkspace(workspaceFile.getAbsolutePath());

    project.getBuildersList()
            .add(new ResultSeekerBuilder(getResultSeeker(), getAutomatedTestCases(), testlink));
}