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:de.mpg.mpdl.inge.xmltransforming.TestBase.java

/**
 * Searches the Java classpath for a given file name and gives back the file (or a
 * FileNotFoundException)./*from  w  w w. j ava 2  s.  com*/
 * 
 * @param fileName The name of the file
 * @return The file
 * @throws FileNotFoundException Thrown if the file was not found.
 */
public static File findFileInClasspath(String fileName) throws FileNotFoundException {
    URL url = TestBase.class.getClassLoader().getResource(fileName);
    if (url == null) {
        throw new FileNotFoundException(fileName);
    }
    return new File(url.getFile());
}

From source file:net.sf.jabref.help.HelpContent.java

private void setPageOnly(URL url) {
    try {//from   w ww .j a v  a2  s. c  o m
        super.setPage(url);
    } catch (IOException ex) {
        if (url == null) {
            System.out.println("Error: Help file not set");
        } else {
            System.out.println("Error: Help file not found '" + url.getFile() + "'");
        }
    }
}

From source file:it.tidalwave.bluemarine2.downloader.impl.SimpleHttpCacheStorage.java

/*******************************************************************************************************************
 *
 * /*from w w w  . ja  v  a2 s.c o  m*/
 *
 ******************************************************************************************************************/
@Nonnull
private Path getCacheItemPath(final @Nonnull URL url) throws MalformedURLException {
    final int port = url.getPort();
    final URL url2 = new URL(url.getProtocol(), url.getHost(), (port == 80) ? -1 : port, url.getFile());
    final Path cachePath = Paths.get(url2.toString().replaceAll(":", ""));
    return folderPath.resolve(cachePath);
}

From source file:com.documentgenerator.view.MainWindow.java

private void loadJson() {

    URL path = ClassLoader.getSystemResource("window.json");
    //System.out.println(path.getAbsolutePath());
    Object obj;//  w w  w . j a  v a 2 s .  co  m
    try {
        obj = parser.parse(new FileReader(path.getFile()));
        jsonObj = (JSONArray) obj;
    } catch (IOException | ParseException ex) {
        ex.printStackTrace();
    }
    //System.out.println(jsonObj);
}

From source file:oz.hadoop.yarn.api.core.ApplicationMasterLauncherImpl.java

/**
 * Will package this application JAR in {@link LocalResource}s.
 * TODO make it more general to allow other resources
 *//*w w w. j a v a2  s.co  m*/
private Map<String, LocalResource> createLocalResources() {
    Map<String, LocalResource> localResources = new LinkedHashMap<String, LocalResource>();
    logger.info(
            "Setting up application classpath by Creating LocalResources and generating JARs if need to. Enable DEBUG for more info.");
    try {
        FileSystem fs = FileSystem.get(this.yarnConfig);

        URL[] cp = ((URLClassLoader) ClassLoader.getSystemClassLoader()).getURLs();
        for (URL url : cp) {
            File f = new File(url.getFile());
            if (f.isDirectory()) {
                String jarFileName = YayaUtils.generateJarFileName(this.applicationName);
                if (logger.isDebugEnabled()) {
                    logger.debug("Creating JAR: " + jarFileName);
                }
                File jarFile = JarUtils.toJar(f, jarFileName);
                this.addToLocalResources(fs, jarFile.getAbsolutePath(), jarFile.getName(),
                        this.applicationId.getId(), localResources);
                try {
                    new File(jarFile.getAbsolutePath()).delete(); // will delete the generated JAR file
                } catch (Exception e) {
                    logger.warn("Failed to delete generated JAR file: " + jarFile.getAbsolutePath(), e);
                }
            } else {
                if (!this.excluded(f.getName())) {
                    this.addToLocalResources(fs, f.getAbsolutePath(), f.getName(), this.applicationId.getId(),
                            localResources);
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Classpath resource " + f.getName()
                                + " is excluded from classpath propagation. You may use"
                                + "classpath.filters file to manage which JARs to exclude from classpath propagation.");
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    return localResources;
}

From source file:cc.arduino.contributions.packages.ContributionInstaller.java

private File download(MultiStepProgress progress, String packageIndexUrl, ProgressListener progressListener)
        throws Exception {
    String statusText = tr("Downloading platforms index...");
    URL url = new URL(packageIndexUrl);
    String[] urlPathParts = url.getFile().split("/");
    File outputFile = BaseNoGui.indexer.getIndexFile(urlPathParts[urlPathParts.length - 1]);
    File tmpFile = new File(outputFile.getAbsolutePath() + ".tmp");
    DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(
            BaseNoGui.indexer.getStagingFolder());
    boolean noResume = true;
    downloader.download(url, tmpFile, progress, statusText, progressListener, noResume);

    Files.deleteIfExists(outputFile.toPath());
    Files.move(tmpFile.toPath(), outputFile.toPath());

    return outputFile;
}

From source file:com.linkedin.pinot.core.plan.maker.MetadataAndDictionaryAggregationPlanMakerTest.java

@BeforeTest
public void buildSegment() throws Exception {
    FileUtils.deleteQuietly(INDEX_DIR);/*from w  w  w .  j  a  v  a2 s  .c  o  m*/
    FileUtils.deleteQuietly(INDEX_DIR_STARTREE);

    // Get resource file path.
    URL resource = getClass().getClassLoader().getResource(AVRO_DATA);
    Assert.assertNotNull(resource);
    String filePath = resource.getFile();

    // Build the segment schema.
    Schema schema = new Schema.SchemaBuilder().setSchemaName("testTable")
            .addMetric("column1", FieldSpec.DataType.INT).addMetric("column3", FieldSpec.DataType.INT)
            .addSingleValueDimension("column5", FieldSpec.DataType.STRING)
            .addSingleValueDimension("column6", FieldSpec.DataType.INT)
            .addSingleValueDimension("column7", FieldSpec.DataType.INT)
            .addSingleValueDimension("column9", FieldSpec.DataType.INT)
            .addSingleValueDimension("column11", FieldSpec.DataType.STRING)
            .addSingleValueDimension("column12", FieldSpec.DataType.STRING)
            .addMetric("column17", FieldSpec.DataType.INT).addMetric("column18", FieldSpec.DataType.INT)
            .addTime("daysSinceEpoch", 1, TimeUnit.DAYS, DataType.INT).build();

    // Create the segment generator config.
    SegmentGeneratorConfig segmentGeneratorConfig = new SegmentGeneratorConfig(schema);
    segmentGeneratorConfig.setInputFilePath(filePath);
    segmentGeneratorConfig.setTableName("testTable");
    segmentGeneratorConfig.setSegmentName(SEGMENT_NAME);
    segmentGeneratorConfig.setOutDir(INDEX_DIR.getAbsolutePath());
    segmentGeneratorConfig.setInvertedIndexCreationColumns(
            Arrays.asList("column6", "column7", "column11", "column17", "column18"));

    // Build the index segment.
    SegmentIndexCreationDriver driver = new SegmentIndexCreationDriverImpl();
    driver.init(segmentGeneratorConfig);
    driver.build();

    // Star Tree segment
    // Build the segment schema.
    schema = new Schema.SchemaBuilder().setSchemaName("testTableStarTree")
            .addMetric("column1", FieldSpec.DataType.INT).addMetric("column3", FieldSpec.DataType.INT)
            .addSingleValueDimension("column5", FieldSpec.DataType.STRING)
            .addSingleValueDimension("column6", FieldSpec.DataType.INT)
            .addSingleValueDimension("column7", FieldSpec.DataType.INT)
            .addSingleValueDimension("column9", FieldSpec.DataType.INT)
            .addSingleValueDimension("column11", FieldSpec.DataType.STRING)
            .addSingleValueDimension("column12", FieldSpec.DataType.STRING)
            .addMetric("column17", FieldSpec.DataType.INT).addMetric("column18", FieldSpec.DataType.INT)
            .addTime("daysSinceEpoch", 1, TimeUnit.DAYS, DataType.INT).build();

    // Create the segment generator config.
    segmentGeneratorConfig = new SegmentGeneratorConfig(schema);
    segmentGeneratorConfig.setInputFilePath(filePath);
    segmentGeneratorConfig.setTableName("testTableStarTree");
    segmentGeneratorConfig.setSegmentName(SEGMENT_NAME_STARTREE);
    segmentGeneratorConfig.setOutDir(INDEX_DIR_STARTREE.getAbsolutePath());
    segmentGeneratorConfig.enableStarTreeIndex(new StarTreeIndexSpec());

    // Build the index segment.
    driver = new SegmentIndexCreationDriverImpl();
    driver.init(segmentGeneratorConfig);
    driver.build();
}

From source file:com.persistent.util.WAStartUp.java

/**
 * Method copy specified file in eclipse plugins folder.
 * @param resourceFile/* www .j ava2s  .c  om*/
 * @param destFile
 */
private void copyResourceFile(String resourceFile, String destFile) {
    URL url = Activator.getDefault().getBundle().getEntry(resourceFile);
    URL fileURL;
    try {
        fileURL = FileLocator.toFileURL(url);
        URL resolve = FileLocator.resolve(fileURL);
        File file = new File(resolve.getFile());
        FileInputStream fis = new FileInputStream(file);
        File outputFile = new File(destFile);
        FileOutputStream fos = new FileOutputStream(outputFile);
        writeFile(fis, fos);
    } catch (IOException e) {
        Activator.getDefault().log(e.getMessage(), e);
    }
}

From source file:net.dontdrinkandroot.lastfm.api.ws.fetcher.DiskBufferedFetcher.java

public DiskBufferedFetcher() throws ParserConfigurationException {

    super();// w w  w.  j a v a2  s .  c  o m

    final URL xmlClassesBase = this.getClass().getClassLoader().getResource("xml/");
    if (xmlClassesBase == null) {
        throw new RuntimeException("XML Directory not found");
    }

    final File file = new File(xmlClassesBase.getFile());
    if (file.exists()) {
        this.xmlWriteBase = new File(file.getParentFile().getParentFile().getParentFile(),
                "src/test/resources/xml/");
        this.logger.info("XML Base found at " + this.xmlWriteBase);
    } else {
        this.logger.info("NO XML Base found at " + this.xmlWriteBase);
    }
}

From source file:eu.planets_project.pp.plato.action.TestDataLoaderImpl.java

/**
 *  Lists all files in a certain directory and with specific extension, e.g. list all files in directory data/project/autoload
 *  with extension .xml. The method can handle both, files in .jar archives and plain ones.
 *  /*  w ww . ja v  a 2s  . c  o m*/
 *  This method has been introduced to be able to handle both, directories in .jar archives and plain directories. We need to be 
 *  able to handle both, zipped and exploded archives, i.e. plato.ear zipped or exploded.
 *  
 *  @param directory directory that shall be browsed
 *  @param fileExtension filter by file extension, e.g. ".xml", ".mm" 
 *  
 *  @return files in the directory
 */
private List<String> listFiles(String directory, String fileExtension)
        throws MalformedURLException, IOException {

    URL url = Thread.currentThread().getContextClassLoader().getResource(directory);
    File dir = new File(url.getFile());
    String directoryPath = dir.getAbsolutePath();

    List<String> files = new ArrayList<String>();

    if (directoryPath.indexOf(".jar!") != -1) {
        URL urlJar = new URL(
                directoryPath.substring(directoryPath.indexOf("file:"), directoryPath.indexOf('!')));

        Enumeration<JarEntry> entries = new JarFile(urlJar.getFile()).entries();

        while (entries.hasMoreElements()) {
            String fileName = entries.nextElement().getName();

            fileName = fileName.replace('\\', '/');

            if (fileName.startsWith(directory) && fileName.endsWith(fileExtension)) {
                files.add(fileName);
            }
        }

    } else {
        File[] fileArray = dir.listFiles();

        for (int i = 0; fileArray != null && i < fileArray.length; i++) {
            String fileName = fileArray[i].getAbsolutePath();

            fileName = fileName.replace('\\', '/');

            int dirStart = fileName.indexOf(directory);

            if (dirStart != -1 && fileName.endsWith(fileExtension)) {
                files.add(fileName.substring(dirStart));
            }
        }
    }
    return files;
}