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.msd.gin.halyard.tools.HalyardExportTest.java

@BeforeClass
public static void setup() throws Exception {
    File rf = File.createTempFile("HalyardExportTest", "");
    rf.delete();/*from   w ww . java 2s.c o  m*/
    rf.mkdirs();
    ROOT = rf.toURI().toURL().toString();
    if (!ROOT.endsWith("/")) {
        ROOT = ROOT + "/";
    }
    ValueFactory vf = SimpleValueFactory.getInstance();
    HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), TABLE, true, 0, true, 0, null);
    sail.initialize();
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                sail.addStatement(vf.createIRI("http://whatever/subj" + i),
                        vf.createIRI("http://whatever/pred" + j), vf.createLiteral("whatever\n\"\\" + k));
            }
        }
    }
    sail.commit();
    sail.shutDown();
    HalyardExport.conf = HBaseServerTestInstance.getInstanceConfig();
}

From source file:com.ibm.watson.developer_cloud.retrieve_and_rank.v1.util.ZipUtils.java

private static void addFilesToZip(final File currentParentDir, final ZipOutputStream out,
        final File globalParentDir) throws IOException {
    for (final File child : currentParentDir.listFiles()) {
        if (child.isDirectory()) {
            addFilesToZip(child, out, globalParentDir);
        } else if (child.isFile()) {
            writeZipEntry(out, globalParentDir.toURI().relativize(child.toURI()).toString(), readBytes(child));
        }//w ww.j  a  v a2 s .co  m
    }
}

From source file:com.qwazr.compiler.JavaCompiler.java

private final static String buildClassPath(File[] classPathArray, Collection<URL> urlCollection)
        throws MalformedURLException, URISyntaxException {
    final List<String> classPathes = new ArrayList<>();

    URLClassLoader classLoader = (URLClassLoader) URLClassLoader.getSystemClassLoader();
    if (classLoader != null && classLoader.getURLs() != null) {
        for (URL url : classLoader.getURLs()) {
            String path = new File(url.toURI()).getAbsolutePath();
            classPathes.add(path);/* w w w  .ja  va  2s .  com*/
            urlCollection.add(url);
        }
    }

    if (classPathArray != null) {
        for (File classPathFile : classPathArray) {
            if (classPathFile.isDirectory()) {
                for (File f : classPathFile.listFiles((FileFilter) FileFileFilter.FILE)) {
                    classPathes.add(f.getAbsolutePath());
                    urlCollection.add(f.toURI().toURL());
                }
            } else if (classPathFile.isFile()) {
                classPathes.add(classPathFile.getAbsolutePath());
                urlCollection.add(classPathFile.toURI().toURL());
            }
        }
    }
    if (classPathes.isEmpty())
        return null;
    return StringUtils.join(classPathes, File.pathSeparator);
}

From source file:ArchiveUtil.java

public static boolean extract(File archive, File targetDir, boolean deleteOnExit) throws IOException {
    return extract(archive.toURI().toURL(), targetDir, deleteOnExit);
}

From source file:com.sunchenbin.store.feilong.core.net.URLUtil.java

/**
 * ?url.//from   w  w  w .  j  ava2 s.  c  om
 *
 * @param filePathName
 *            
 * @return url
 * @see java.io.File#toURI()
 * @see java.net.URI#toURL()
 * @since 1.4.0
 */
public static URL getFileURL(String filePathName) {
    if (Validator.isNullOrEmpty(filePathName)) {
        throw new NullPointerException("filePathName can't be null/empty!");
    }
    File file = new File(filePathName);
    try {
        // file.toURL() ?,? URL ?
        return file.toURI().toURL();
    } catch (MalformedURLException e) {
        LOGGER.error("MalformedURLException:", e);
        throw new URIParseException(e);
    }
}

From source file:com.asakusafw.compiler.bootstrap.BatchCompilerDriver.java

private static boolean start(String[] args) throws Exception {
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(OPTIONS, args);
    String output = cmd.getOptionValue(OPT_OUTPUT.getOpt());
    String className = cmd.getOptionValue(OPT_CLASS.getOpt());
    String packageName = cmd.getOptionValue(OPT_PACKAGE.getOpt());
    String hadoopWork = cmd.getOptionValue(OPT_HADOOPWORK.getOpt());
    String compilerWork = cmd.getOptionValue(OPT_COMPILERWORK.getOpt());
    String link = cmd.getOptionValue(OPT_LINK.getOpt());
    String plugin = cmd.getOptionValue(OPT_PLUGIN.getOpt());

    File outputDirectory = new File(output);
    Location hadoopWorkLocation = Location.fromPath(hadoopWork, '/');
    File compilerWorkDirectory = new File(compilerWork);
    List<File> linkingResources = new ArrayList<>();
    if (link != null) {
        for (String s : link.split(File.pathSeparator)) {
            linkingResources.add(new File(s));
        }/*from  w ww. java 2s . c om*/
    }
    List<URL> pluginLocations = new ArrayList<>();
    if (plugin != null) {
        for (String s : plugin.split(File.pathSeparator)) {
            if (s.trim().isEmpty()) {
                continue;
            }
            try {
                File file = new File(s);
                if (file.exists() == false) {
                    throw new FileNotFoundException(file.getAbsolutePath());
                }
                URL url = file.toURI().toURL();
                pluginLocations.add(url);
            } catch (IOException e) {
                LOG.warn(MessageFormat.format(Messages.getString("BatchCompilerDriver.warnFailedToLoadPlugin"), //$NON-NLS-1$
                        s), e);
            }
        }
    }

    Class<? extends BatchDescription> batchDescription = Class.forName(className)
            .asSubclass(BatchDescription.class);
    boolean succeeded = compile(outputDirectory, batchDescription, packageName, hadoopWorkLocation,
            compilerWorkDirectory, linkingResources, pluginLocations);

    if (succeeded) {
        LOG.info(MessageFormat.format(Messages.getString("BatchCompilerDriver.infoComplete"), //$NON-NLS-1$
                batchDescription.getName()));
    }
    return succeeded;
}

From source file:com.autentia.tnt.util.ReportUtil.java

/**
 * Obtiene un report de la aplicacin. segun el parametro canBeOverrided el
 * report se toamra del classpath, o bien se puede sobreescribir de la ruta
 * externa de usuario/*from  w  w  w.j  a v a 2s.  c  o m*/
 * 
 * @param reportName
 *            nombre del report, sin extension (document/ficha.de.pedido);
 *            (billing/Informe.de.facturas.recibidas)
 * @param canBeOverrided
 *            si se puede sobreescribir el informe o bien se toma siempre
 *            del classpath
 * @return
 */
public static URL getReportStream(String reportName, String postfix, boolean canBeOverrided) {

    URL reportUrl = null;

    if (canBeOverrided) {
        String overridePath = ConfigurationUtil.getDefault().getReportPath() + "/override/" + reportName;
        try {
            final File file = new File(overridePath + postfix);
            if (file.exists()) {
                reportUrl = file.toURI().toURL();
            }
        } catch (MalformedURLException e) {
            log.info("report: " + reportName + " is not override. i'll try to find in classpath");
        }

    }

    // aun no hemos encontrado el report
    if (reportUrl == null) {
        reportUrl = Thread.currentThread().getContextClassLoader()
                .getResource(REPORT_PREFIX + reportName + postfix);
    }

    return reportUrl;
}

From source file:net.sourceforge.dita4publishers.tools.dxp.DitaDxpHelper.java

/**
 * Extracts only the local dependencies used from a map from a DXP package.
 * @param zipFile/*from w  w w .  j  a  va 2  s .  c o m*/
 * @param mapEntry
 * @param outputDir
 * @param dxpOptions
 * @throws Exception 
 */
private static void extractMap(ZipFile zipFile, ZipEntry mapEntry, File outputDir,
        MapBosProcessorOptions dxpOptions) throws Exception {
    Map<URI, Document> domCache = new HashMap<URI, Document>();

    if (!dxpOptions.isQuiet())
        log.info("Extracting map " + mapEntry.getName() + "...");

    BosConstructionOptions bosOptions = new BosConstructionOptions(log, domCache);

    InputSource source = new InputSource(zipFile.getInputStream(mapEntry));

    File dxpFile = new File(zipFile.getName());

    URL baseUri = new URL("jar:" + dxpFile.toURI().toURL().toExternalForm() + "!/");
    URL mapUrl = new URL(baseUri, mapEntry.getName());

    source.setSystemId(mapUrl.toExternalForm());

    Document rootMap = DomUtil.getDomForSource(source, bosOptions, false);
    DitaBoundedObjectSet mapBos = DitaBosHelper.calculateMapBos(bosOptions, log, rootMap);

    MapCopyingBosVisitor visitor = new MapCopyingBosVisitor(outputDir);
    visitor.visit(mapBos);
    if (!dxpOptions.isQuiet())
        log.info("Map extracted.");
}

From source file:com.textocat.textokit.corpus.statistics.dao.corpus.XmiFileTreeCorpusDAO.java

static public TypeSystemDescription getTypeSystem(String corpusPathString)
        throws SAXException, IOException, ParserConfigurationException {
    for (File f : new File(corpusPathString).listFiles((FileFilter) new WildcardFileFilter("*.xml"))) {
        if (getXMLRootElement(f).equals("typeSystemDescription")) {
            return createTypeSystemDescriptionFromPath(f.toURI().toString());
        }//from   w w w .  j  a  v a  2  s  .com
    }
    throw new FileNotFoundException();
}

From source file:org.fcrepo.camel.karaf.KarafIT.java

private static String getBundleUri(final String artifactId, final String version) {
    final File artifact = new File(
            getBaseDir() + "/../" + artifactId + "/target/" + artifactId + "-" + version + ".jar");
    if (artifact.exists()) {
        return artifact.toURI().toString();
    }/*  w w  w .ja  v  a  2  s.  c o  m*/
    return "mvn:org.fcrepo.camel/" + artifactId + "/" + version;
}