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:iristk.cfg.ABNFGrammar.java

public ABNFGrammar(File file) throws IOException, GrammarException {
    this(file.toURI());
}

From source file:se.crisp.codekvast.agent.daemon.appversion.ManifestAppVersionStrategy.java

private URL search(File dir, String regex) throws MalformedURLException {
    if (!dir.isDirectory()) {
        log.warn("{} is not a directory", dir);
        return null;
    }//from ww w.  j a va 2 s  .c om

    File[] files = dir.listFiles();

    if (files != null) {
        for (File file : files) {
            if (file.isFile() && file.getName().matches(regex)) {
                log.debug("Found {}", file);
                return new URL(file.toURI().toString());
            }
        }
        for (File file : files) {
            if (file.isDirectory()) {
                URL url = search(file, regex);
                if (url != null) {
                    return url;
                }
            }
        }
    }
    return null;
}

From source file:edu.berkeley.compbio.phyloutils.HugenholtzTaxonomyService.java

private synchronized static InputStream getInputStream(String filename)
        throws PhyloUtilsException, IOException {
    //ClassLoader classClassLoader = new NewickParser().getClass().getClassLoader();
    ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader();
    //ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();

    //URL res1 = classClassLoader.getResource(filename);
    URL res = threadClassLoader.getResource(filename);
    //URL res3 = systemClassLoader.getResource(filename);

    if (res == null) {
        File f = new File(filename);
        if (f.exists()) {
            res = f.toURI().toURL(); // new URL("file://" + filename);
        }//from  ww w  . ja v a2  s. co  m
    }

    if (res == null) {
        logger.error("file not found: " + filename);
        //Get the System Classloader
        //ClassLoader.getSystemClassLoader();

        //Get the URLs
        URL[] urls = ((URLClassLoader) threadClassLoader).getURLs();

        for (int i = 0; i < urls.length; i++) {
            logger.warn(urls[i].getFile());
        }

        throw new PhyloUtilsException("file not found: " + filename);
    }

    InputStream is = res.openStream();
    is = filename.endsWith(".gz") ? new GZIPInputStream(is) : is;
    /*if (is == null)
        {
        is = new FileInputStream(filename);
        }*/
    return is;
}

From source file:eu.planets_project.services.utils.DigitalObjectUtilsTests.java

@Test
public void toFileDigitalObject() throws MalformedURLException, IOException {
    DigitalObject object = new DigitalObject.Builder(Content.byReference(testZip)).build();
    File file = DigitalObjectUtils.toFile(object);
    Assert.assertTrue(// w  ww  .ja v a  2s . c om
            IOUtils.contentEquals(object.getContent().getInputStream(), file.toURI().toURL().openStream()));
}

From source file:eu.scape_project.droid_identify.droid.DroidIdentificationTask.java

/**
 * Run droid identification on file//from   w w w. j  av a  2  s .  c  o  m
 *
 * @param filePath Absolute file path (local/hdfs)
 * @return Result list
 */
public String identify(String filePath) {
    InputStream in = null;
    String puid = "fmt/0";
    IdentificationRequest request = null;
    try {

        File file = new File(filePath);
        URI resourceUri = file.toURI();
        // check if the file is available in the local file system and try
        // to open a hdfs stream otherwise
        if (file.exists()) {
            in = new FileInputStream(file);
        } else {
            Path hdfsPath = new Path(filePath);
            in = hdfs.open(hdfsPath);
        }

        LOG.debug("Identification of resource: " + resourceUri.toString());
        RequestMetaData metaData = new RequestMetaData(file.length(), file.lastModified(), file.getName());
        LOG.debug("File length: " + file.length());
        LOG.debug("File modified: " + file.lastModified());
        LOG.debug("File name: " + file.getName());
        RequestIdentifier identifier = new RequestIdentifier(resourceUri);
        request = new FileSystemIdentificationRequest(metaData, identifier);
        request.open(in);
        IdentificationResultCollection results = bsi.matchBinarySignatures(request);
        bsi.removeLowerPriorityHits(results);
        if (results == null || results.getResults() == null || results.getResults().isEmpty()) {
            LOG.warn("No identification result");
        } else {
            List<IdentificationResult> result = results.getResults();
            if (result != null && !result.isEmpty()) {
                for (IdentificationResult ir : result) {
                    String id = ir.getPuid();
                    if (id != null && !id.isEmpty()) {
                        // take first puid, ignore others
                        puid = id;
                        break;
                    }
                }
            }
            if (puid.isEmpty()) {
                puid = "fmt/0"; // unknown
            }
        }
        request.close();
    } catch (IOException ex) {
        LOG.error("I/O Exception", ex);
    } finally {
        IOUtils.closeQuietly(in);
        if (request != null) {
            try {
                request.close();
            } catch (IOException ex) {
                LOG.warn("I/O Exception");
            }
        }
    }

    return puid;
}

From source file:architecture.ee.jdbc.sqlquery.factory.impl.AbstractSqlQueryFactory.java

public boolean fileDeleted(File file) {
    if (configuration.isResourceLoaded(file.toURI().toString())) {
        configuration.removeUriNamespace(file.toURI().toString(), true);
        configuration.removeLoadedResource(file.toURI().toString());
    }/*from w ww  .j  a  v  a 2s.  c  o m*/
    // DeployedInfo di =
    deployments.remove(file.toURI());
    // ToDo more ...
    return true;
}

From source file:com.datatorrent.stram.client.StramClientUtils.java

public static void copyFromLocalFileNoChecksum(FileSystem fs, File fromLocal, Path toDFS) throws IOException {
    // This is to void the hadoop FileSystem API to perform checksum on the local file
    // This "feature" has caused a lot of headache because the local file can be copied from HDFS and modified,
    // and the checksum will fail if the file is again copied to HDFS
    try {/*from   w ww  . j  a  va 2 s  .  c  om*/
        new File(fromLocal.getParentFile(), "." + fromLocal.getName() + ".crc").delete();
    } catch (Exception ex) {
        // ignore
    }
    fs.copyFromLocalFile(new Path(fromLocal.toURI()), toDFS);
}

From source file:com.searchbox.framework.service.DirectoryService.java

public String getApplicationRelativePath(File file) {
    try {// ww w.j av a  2s .  c o m
        LOGGER.debug("Application absolutePath: " + context.getResource("").getFile().getAbsolutePath());
        String relative = context.getResource("").getFile().toURI().relativize(file.toURI()).getPath();
        return relative;
    } catch (IOException e) {
        LOGGER.error("Could not get application-relative path in directoryService", e);
    }
    return null;
}

From source file:architecture.ee.jdbc.sqlquery.factory.impl.AbstractSqlQueryFactory.java

public String fileCreated(File file) {
    try {/*from   w  w w . j  av a  2 s. co  m*/
        URI uri = file.toURI();
        if (deployments.containsKey(uri)) {
            DeployedInfo di = deployments.get(uri);
            if (di.timestamp == file.lastModified()) {
                return "";
            }
        } else {
            buildSqlFromInputStream(new FileInputStream(file), configuration);
            DeployedInfo di = new DeployedInfo(file.toURI(), System.currentTimeMillis());
            di.timestamp = file.lastModified();
            deployments.put(di.uri, di);
        }
    } catch (FileNotFoundException e) {

    }
    return "success";
}

From source file:cross.io.InputDataFactory.java

@Override
public TupleND<IFileFragment> prepareInputData(String[] input) {
    if (input == null || input.length == 0) {
        throw new ExitVmException("No input data given, aborting!");
    }//  ww  w .  j  a v a 2s . c o m
    log.info("Preparing input data!");
    log.debug("Received paths: {}", Arrays.toString(input));
    this.initialFiles = new ArrayList<>();
    for (String s : input) {
        File inputFile = new File(s);
        URI uri = null;
        if (inputFile.isFile() && inputFile.exists()) {
            uri = inputFile.toURI();
        } else {
            uri = URI.create(FileTools.escapeUri(s));
        }
        if (uri.getScheme() != null) {
            this.initialFiles.add(new FileFragment(uri));
        } else {
            for (File f : getInputFiles(new String[] { s })) {
                log.info("Adding file {}", f.getAbsolutePath());
                initialFiles.add(new FileFragment(f.toURI()));
            }
        }
    }

    if (initialFiles.isEmpty()) {
        throw new ExitVmException("Could not create input data for files " + Arrays.toString(input));
    }
    return new TupleND<>(initialFiles);
}