Example usage for java.io File toURI

List of usage examples for java.io File toURI

Introduction

In this page you can find the example usage for java.io File toURI.

Prototype

public URI toURI() 

Source Link

Document

Constructs a file: URI that represents this abstract pathname.

Usage

From source file:com.github.jknack.handlebars.io.FileTemplateLoader.java

@Override
protected URL getResource(final String location) throws IOException {
    File file = new File(location);
    return file.exists() ? file.toURI().toURL() : null;
}

From source file:com.splicemachine.orc.OrcTester.java

static RecordWriter createOrcRecordWriter(File outputFile, Format format, Compression compression,
        ObjectInspector columnObjectInspector) throws IOException {
    JobConf jobConf = new JobConf();
    jobConf.set("hive.exec.orc.write.format", format == ORC_12 ? "0.12" : "0.11");
    jobConf.set("hive.exec.orc.default.compress", compression.name());

    return new OrcOutputFormat().getHiveRecordWriter(jobConf, new Path(outputFile.toURI()), Text.class,
            compression != NONE, createTableProperties("test", columnObjectInspector.getTypeName()), () -> {
            });//w ww .  j a va 2  s . co  m
}

From source file:com.github.robozonky.cli.StrategyValidationFeature.java

public StrategyValidationFeature(final File location) throws MalformedURLException {
    this(location.toURI().toURL());
}

From source file:com.ngdata.hbaseindexer.mr.TestUtils.java

private static EmbeddedSolrServer createEmbeddedSolrServer(File solrHomeDir, FileSystem fs, Path outputShardDir)
        throws IOException {

    LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHomeDir + ", fs: " + fs
            + ", outputShardDir: " + outputShardDir);

    // copy solrHomeDir to ensure it isn't modified across multiple unit tests or multiple EmbeddedSolrServer instances
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();//  w  w  w  .  ja v  a2s.c  om
    FileUtils.copyDirectory(solrHomeDir, tmpDir);
    solrHomeDir = tmpDir;

    Path solrDataDir = new Path(outputShardDir, "data");

    String dataDirStr = solrDataDir.toUri().toString();

    SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrHomeDir.toString()), null, null);

    LOG.info(String.format(Locale.ENGLISH,
            "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to solr.data.dir %s, with permdir %s",
            solrHomeDir, solrHomeDir.toURI(), loader.getInstancePath(), loader.getConfigDir(), dataDirStr,
            outputShardDir));

    // TODO: This is fragile and should be well documented
    System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName());
    System.setProperty("solr.lock.type", DirectoryFactory.LOCK_TYPE_HDFS);
    System.setProperty("solr.hdfs.nrtcachingdirectory", "false");
    System.setProperty("solr.hdfs.blockcache.enabled", "false");
    System.setProperty("solr.autoCommit.maxTime", "600000");
    System.setProperty("solr.autoSoftCommit.maxTime", "-1");

    CoreContainer container = new CoreContainer(loader);
    container.load();

    SolrCore core = container.create("core1", Paths.get(solrHomeDir.toString()),
            ImmutableMap.of(CoreDescriptor.CORE_DATADIR, dataDirStr), false);

    if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) {
        throw new UnsupportedOperationException(
                "Invalid configuration. Currently, the only DirectoryFactory supported is "
                        + HdfsDirectoryFactory.class.getSimpleName());
    }

    EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "core1");
    return solr;
}

From source file:com.lizardtech.expresszip.model.Job.java

public static FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource(File cropFile)
        throws MalformedURLException, IOException {
    Map<String, Serializable> connectParameters = new java.util.HashMap<String, Serializable>();
    connectParameters.put("url", cropFile.toURI().toURL());
    connectParameters.put("create spatial index", true);
    DataStore dataStore = DataStoreFinder.getDataStore(connectParameters);
    if (dataStore == null)
        throw new RuntimeException("No DataStore found to handle" + cropFile.getPath());
    String[] typeNames = dataStore.getTypeNames();
    String typeName = typeNames[0];
    FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = (FeatureSource<SimpleFeatureType, SimpleFeature>) dataStore
            .getFeatureSource(typeName);
    return featureSource;
}

From source file:com.yahoo.gondola.container.impl.ZookeeperConfigProviderTest.java

@Test
public void testGetConfigFile() throws Exception {
    File configFile = configProvider.getConfigFile();
    assertTrue(Arrays.equals(IOUtils.toByteArray(configFile.toURI()), IOUtils.toByteArray(file)));
}

From source file:com.skcraft.launcher.install.InstallLog.java

private String relativize(File child) {
    checkNotNull(baseDir);//  w w  w.  java 2s.  c o  m
    URI uri = child.toURI();
    String relative = baseDir.toURI().relativize(uri).getPath();
    if (relative.equals(uri.toString())) {
        throw new IllegalArgumentException("Child path not in base");
    }
    return relative;
}

From source file:com.stehno.sanctuary.core.remote.S3RemoteStore.java

private String extractKey(File rootDirectory, File file) {
    return file.toURI().toString().replace(rootDirectory.toURI().toString(), "");
}

From source file:com.serli.maven.plugin.quality.mojo.LicenseMojo.java

/**
 * @param project// w  w w.  ja v  a  2  s .c o m
 *          not null
 * @param url
 *          not null
 * @return a valid URL object from the url string
 * @throws IOException
 *           if any
 */
protected static URL getLicenseURL(MavenProject project, String url) throws IOException {
    URL licenseUrl = null;
    UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES);
    // UrlValidator does not accept file URLs because the file
    // URLs do not contain a valid authority (no hostname).
    // As a workaround accept license URLs that start with the
    // file scheme.
    if (urlValidator.isValid(url) || StringUtils.defaultString(url).startsWith("file://")) {
        try {
            licenseUrl = new URL(url);
        } catch (MalformedURLException e) {
            throw new MalformedURLException(
                    "The license url '" + url + "' seems to be invalid: " + e.getMessage());
        }
    } else {
        File licenseFile = new File(project.getBasedir(), url);
        if (!licenseFile.exists()) {
            // Workaround to allow absolute path names while
            // staying compatible with the way it was...
            licenseFile = new File(url);
        }
        if (!licenseFile.exists()) {
            throw new IOException("Maven can't find the file '" + licenseFile + "' on the system.");
        }
        try {
            licenseUrl = licenseFile.toURI().toURL();
        } catch (MalformedURLException e) {
            throw new MalformedURLException(
                    "The license url '" + url + "' seems to be invalid: " + e.getMessage());
        }
    }

    return licenseUrl;
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    String workingDir = System.getProperty("user.dir");
    final File f = new File(workingDir, "../media/omgrobots.flv");

    final Media m = new Media(f.toURI().toString());
    final MediaPlayer mp = new MediaPlayer(m);
    final MediaView mv = new MediaView(mp);

    final DoubleProperty width = mv.fitWidthProperty();
    final DoubleProperty height = mv.fitHeightProperty();

    width.bind(Bindings.selectDouble(mv.sceneProperty(), "width"));
    height.bind(Bindings.selectDouble(mv.sceneProperty(), "height"));

    mv.setPreserveRatio(true);/*from  w w w  .  ja  va2  s  .c o  m*/

    StackPane root = new StackPane();
    root.getChildren().add(mv);

    final Scene scene = new Scene(root, 960, 540);
    scene.setFill(Color.BLACK);

    primaryStage.setScene(scene);
    primaryStage.setTitle("Full Screen Video Player");
    primaryStage.setFullScreen(true);
    primaryStage.show();

    mp.play();
}