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.linkedin.pinot.core.segment.index.loader.LoaderTest.java

@BeforeClass
public void setUp() throws Exception {
    FileUtils.deleteQuietly(INDEX_DIR);/*w w w  . j  a va2 s. c  o m*/

    URL resourceUrl = getClass().getClassLoader().getResource(AVRO_DATA);
    Assert.assertNotNull(resourceUrl);
    _avroFile = new File(resourceUrl.getFile());

    _v1IndexLoadingConfig = new IndexLoadingConfig();
    _v1IndexLoadingConfig.setReadMode(ReadMode.mmap);
    _v1IndexLoadingConfig.setSegmentVersion(SegmentVersion.v1);

    _v3IndexLoadingConfig = new IndexLoadingConfig();
    _v3IndexLoadingConfig.setReadMode(ReadMode.mmap);
    _v3IndexLoadingConfig.setSegmentVersion(SegmentVersion.v3);
}

From source file:gobblin.data.management.copy.converter.DecryptConverterTest.java

@Test
public void testConvertDifferentEncryption() throws IOException, DataConversionException {
    final String expectedFileContents = "2345678";

    WorkUnitState workUnitState = new WorkUnitState();
    workUnitState.getJobState().setProp("converter.encrypt." + EncryptionConfigParser.ENCRYPTION_ALGORITHM_KEY,
            "insecure_shift");

    try (DecryptConverter converter = new DecryptConverter()) {
        converter.init(workUnitState);/*from  w  w  w.ja  v  a  2s.  c  o  m*/
        FileSystem fs = FileSystem.getLocal(new Configuration());

        URL url = getClass().getClassLoader()
                .getResource("decryptConverterTest/decrypt-test.txt.insecure_shift");
        Assert.assertNotNull(url);

        String testFilePath = url.getFile();
        try (FSDataInputStream testFileInput = fs.open(new Path(testFilePath))) {
            FileAwareInputStream fileAwareInputStream = new FileAwareInputStream(
                    CopyableFileUtils.getTestCopyableFile(), testFileInput);
            fileAwareInputStream.getFile()
                    .setDestination(new Path("file:///tmp/decrypt-test.txt.insecure_shift"));
            Iterable<FileAwareInputStream> iterable = converter.convertRecord("outputSchema",
                    fileAwareInputStream, workUnitState);
            FileAwareInputStream decryptedStream = Iterables.getFirst(iterable, null);
            Assert.assertNotNull(decryptedStream);

            String actual = IOUtils.toString(decryptedStream.getInputStream(), Charsets.UTF_8);
            Assert.assertEquals(actual, expectedFileContents);
            Assert.assertEquals(decryptedStream.getFile().getDestination().getName(), "decrypt-test.txt");
        }
    }
}

From source file:ch.kostceco.bento.sipval.service.impl.ConfigurationServiceImpl.java

@Override
public String getPathOfDroidSignatureFile() throws MalformedURLException {

    String pathSignature = getPathToDroidSignatureFile();

    File fileSigfile = new File(pathSignature);
    URL urlSigfile = fileSigfile.toURI().toURL();
    String result = urlSigfile.getFile();

    return result;
}

From source file:com.webautomation.ScreenCaptureHtmlUnitDriver.java

String mapLocalUrl(HtmlPage page, URL link, String path, Map<String, String> replacementToAdd)
        throws Exception {
    String resultingFileName = "resources/" + FilenameUtils.getName(link.getFile());
    replacementToAdd.put(path, resultingFileName);
    return resultingFileName;
}

From source file:net.desgrange.pwad.service.PwadServiceTest.java

@Test
public void testDownloadPicture() throws Exception {
    final File outputFolder = testFolder.newFolder("output_folder");
    final URL pictureFile = getClass().getResource("/pictures/100_0001.JPG");
    final Picture picture = new Picture();
    picture.setName("01.JPG");
    picture.setUrl("file://" + pictureFile.getFile());

    pwadService.downloadPicture(picture, outputFolder);
    assertTrue(FileUtils.contentEquals(new File(pictureFile.toURI()), outputFolder.listFiles()[0]));
}

From source file:at.tuwien.minimee.migration.engines.MonitorEngineTOPDefault.java

/**
 * Copies resource file 'from' from destination 'to' and set execution permission.
 * //from   www . jav a  2 s. c o  m
 * @param from
 * @param to
 * @throws Exception
 */
protected void copyFile(String from, String to, String workingDirectory) throws Exception {

    //
    // copy the shell script to the working directory
    //
    URL monitorCallShellScriptUrl = Thread.currentThread().getContextClassLoader().getResource(from);
    File f = new File(monitorCallShellScriptUrl.getFile());
    String directoryPath = f.getAbsolutePath();
    // if the application was created as exploded archive, the absolute path is a real filename
    String fileName = from;
    InputStream in = null;
    if (directoryPath.indexOf(".jar!") > -1) {
        // this class is not in an exploded archive, extract the filename  
        URL urlJar = new URL(
                directoryPath.substring(directoryPath.indexOf("file:"), directoryPath.indexOf('!')));

        JarFile jf = new JarFile(urlJar.getFile());
        JarEntry je = jf.getJarEntry(from);
        fileName = je.getName();
        in = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
    } else {
        in = new FileInputStream(f);
    }

    File outScriptFile = new File(to);

    FileOutputStream fos = new FileOutputStream(outScriptFile);
    int nextChar;
    while ((nextChar = in.read()) != -1)
        fos.write(nextChar);

    fos.flush();
    fos.close();

    //
    // This seems kind of hard core, but we have to set execution rights for the shell script, 
    // otherwise we wouldn't be allowed to execute it.
    // The Java-way with FilePermission didn't work for some reason.
    //
    try {
        LinuxCommandExecutor cmdExecutor = new LinuxCommandExecutor();
        cmdExecutor.setWorkingDirectory(workingDirectory);

        cmdExecutor.runCommand("chmod 777 " + to);
    } catch (Exception e) {
        throw e;
    }
}

From source file:com.collective.celos.ci.deploy.JScpWorkerTest.java

@Test
public void testGetFileObjectByUriStringParam() throws Exception {
    JScpWorker worker = new JScpWorker("uname");
    URL res = Thread.currentThread().getContextClassLoader()
            .getResource("com/collective/celos/ci/testing/config/target.json");
    FileObject object = worker.getFileObjectByUri(res.toURI().toString());
    IOUtils.contentEquals(object.getContent().getInputStream(), new FileInputStream(res.getFile()));
}

From source file:eu.scape_project.pt.proc.ToolProcessorTest.java

@Before
public void setUp() {
    try {//from   w ww .j a v a2 s . co  m
        URL res = this.getClass().getClassLoader().getResource("toolspecs");
        // use the file toolspec xml as the input file too (for this test)
        toolspecsDir = res.getFile();
        repo = new LocalToolRepository(res.getFile());

    } catch (IOException ex) {
        fail(ex.getMessage());
    }

}

From source file:ch.silviowangler.dox.AbstractIntegrationTest.java

protected File loadFile(String fileName) {
    URL resource = getClass().getClassLoader().getResource(fileName);
    final File file = FileUtils.toFile(resource);
    assert file != null && file.exists() : "File '" + fileName + "' does not exist. Resource "
            + resource.getFile();
    return file;//from w w w  .  j av a  2  s.c o  m
}

From source file:com.videobox.web.util.dwr.AutoAnnotationDiscoveryContainer.java

private StringBuilder scanLoader(StringBuilder sb, String pkg) throws IOException {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    URL url = findResource(loader, pkg.replace('.', '/'));
    if (url == null) {
        return null;
    }// w ww  .  j  av a 2s.co m
    String dirPath = url.getFile();
    File dir = new File(dirPath);
    return scanLoader(sb, dir);
}