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.liferay.arquillian.maven.internal.tasks.ToolsClasspathTask.java

/**
 * (non-Javadoc)//  ww  w.  j  a va 2 s.  co m
 * @see
 * org.jboss.shrinkwrap.resolver.impl.maven.task.MavenWorkingSessionTask
 * #execute(org.jboss.shrinkwrap.resolver.api.maven.MavenWorkingSession)
 */
@Override
public URLClassLoader execute(MavenWorkingSession session) {
    final ParsedPomFile pomFile = session.getParsedPomFile();

    LiferayPluginConfiguration configuration = new LiferayPluginConfiguration(pomFile);

    System.setProperty("liferayVersion", configuration.getLiferayVersion());

    File appServerLibGlobalDir = new File(configuration.getAppServerLibGlobalDir());

    File appServerLibPortalDir = new File(configuration.getAppServerLibPortalDir());

    List<URI> liferayToolArchives = new ArrayList<>();

    if ((appServerLibGlobalDir != null) && appServerLibGlobalDir.exists()) {

        // app server global libraries

        Collection<File> appServerLibs = FileUtils.listFiles(appServerLibGlobalDir, new String[] { "jar" },
                true);

        for (File file : appServerLibs) {
            liferayToolArchives.add(file.toURI());
        }

        // All Liferay Portal Lib jars

        Collection<File> liferayPortalLibs = FileUtils.listFiles(appServerLibPortalDir, new String[] { "jar" },
                true);

        for (File file : liferayPortalLibs) {
            liferayToolArchives.add(file.toURI());
        }

        // Util jars

        File[] utilJars = Maven.resolver().loadPomFromClassLoaderResource("liferay-tool-deps.xml")
                .importCompileAndRuntimeDependencies().resolve().using(AcceptAllStrategy.INSTANCE).asFile();

        for (int i = 0; i < utilJars.length; i++) {
            liferayToolArchives.add(utilJars[i].toURI());
        }
    }

    if (_log.isTraceEnabled()) {
        _log.trace("Jars count in Tools classpath Archive:" + liferayToolArchives.size());
    }

    List<URL> classpathUrls = new ArrayList<>();

    try {
        if (!liferayToolArchives.isEmpty()) {
            ListIterator<URI> toolsJarItr = liferayToolArchives.listIterator();
            while (toolsJarItr.hasNext()) {
                URI jarURI = toolsJarItr.next();
                classpathUrls.add(jarURI.toURL());
            }
        }
    } catch (MalformedURLException e) {
        _log.error("Error building Tools classpath", e);
    }

    return new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()]), null);
}

From source file:de.alpharogroup.io.StringOutputStreamTest.java

/**
 * Test method for {@link StringOutputStream#toString()}
 *
 * @throws IOException//w w w.  j  a va  2  s .  c o  m
 *             Signals that an I/O exception has occurred.
 */
@Test
public void testToString() throws IOException {
    final String expected = "Thu Apr 19 00:00:00 CEST 2012";
    final File writeInMe = new File(".", "testWriteBirthdayToFile.log");
    FileUtils.writeStringToFile(writeInMe, expected);
    final InputStream inputStream = writeInMe.toURI().toURL().openStream();
    final StringOutputStream stringOutput = new StringOutputStream();

    final byte[] buffer = new byte[8192];
    int readLength;
    while ((readLength = inputStream.read(buffer, 0, buffer.length)) != -1) {
        stringOutput.write(buffer, 0, readLength);
    }

    final String actual = stringOutput.toString();
    stringOutput.close();
    AssertJUnit.assertTrue("", actual.startsWith(expected));
    FileUtils.deleteQuietly(writeInMe);
}

From source file:foam.nanos.blob.HttpBlobService.java

protected void download(X x) {
    OutputStream os = null;//from  w ww  .  ja  v  a 2s. co  m
    HttpServletRequest req = x.get(HttpServletRequest.class);
    HttpServletResponse resp = x.get(HttpServletResponse.class);

    try {
        String path = req.getRequestURI();
        String id = path.replaceFirst("/service/" + nspec_.getName() + "/", "");

        Blob blob = getDelegate().find(id);
        if (blob == null) {
            resp.setStatus(resp.SC_NOT_FOUND);
            return;
        }

        long size = blob.getSize();
        resp.setStatus(resp.SC_OK);
        if (blob instanceof FileBlob) {
            File file = ((FileBlob) blob).getFile();
            resp.setContentType(Files.probeContentType(Paths.get(file.toURI())));
        } else {
            resp.setContentType("application/octet-stream");
        }
        resp.setHeader("Content-Length", Long.toString(size, 10));
        resp.setHeader("ETag", id);
        resp.setHeader("Cache-Control", "public");

        os = resp.getOutputStream();
        blob.read(os, 0, size);
        os.close();
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException(t);
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:org.bitsofinfo.util.address.usps.ais.source.Zip4SourceDataExtractor.java

private void collectHandles(List<FileHandle> handles, File dir) {
    File[] contents = dir.listFiles();
    for (File f : contents) {
        if (f.isFile()) {
            FileHandle handle = new FileHandle(f.toURI());
            handle.setProperty("identifier", dir.getName());
            if (f.getAbsolutePath().indexOf("ctystate") != -1) {
                handle.setProperty(USPSDataLoader.FILE_HANDLE_PROP_USPS_PRODUCT_TYPE,
                        USPSProductType.CITY_STATE);
            } else {
                handle.setProperty(USPSDataLoader.FILE_HANDLE_PROP_USPS_PRODUCT_TYPE,
                        USPSProductType.ZIP_PLUS_4);
            }// w w  w .  j  av a  2s. c o  m
            handles.add(handle);
        } else {
            collectHandles(handles, f);
        }
    }
}

From source file:com.comcast.cats.configuration.StringsDMHandler.java

/**
 * Return the local path URI for strings.dm.
 * //ww  w.  j av  a2  s. c o  m
 * @param catsHome
 *            - String representing the CATS_HOME location.
 * @return
 * @throws URISyntaxException
 */
private URI getStringsDMFileLocation(String catsHome) throws URISyntaxException {
    /*
     * For now, turn this into a file and then return the URI from the file.
     * It might make more sense to use URL, since this is a locator.
     */
    File catsHomeDir = new File(catsHome + "/tmp/" + STRINGS_DM_LOCATION);
    return catsHomeDir.toURI();
}

From source file:com.helegris.szorengeteg.ui.MediaLoader.java

/**
 * Creates playable JavaFX audio from a byte array. To achieve this, it
 * creates and deletes a temporary file.
 *
 * @param audioBytes//from  w  w w  .j  a  v  a 2  s.c o  m
 * @return audio
 * @throws IOException
 */
public Media loadAudio(byte[] audioBytes) throws IOException {
    File tempFile = File.createTempFile("audio", null);
    tempFile.deleteOnExit();
    IOUtils.write(audioBytes, new FileOutputStream(tempFile));
    Media media = new Media(tempFile.toURI().toString());
    return media;
}

From source file:com.linkage.utils.wsdl.support.UrlWsdlLoader.java

/**
 * function   building XmlObject/*from  w w  w .  ja  va2 s .  c  o  m*/
 */
public XmlObject load(String url, XmlOptions option) throws XmlException, IOException, Exception {
    XmlObject object = null;
    if (!PathUtils.isHttpPath(url)) {
        try {
            File file = new File(url.replace('/', File.separatorChar));
            if (file.exists())
                url = file.toURI().toURL().toString();
        } catch (Exception e) {
        }
    }

    if (wsdlcache.containsKey(url)) {
        return wsdlcache.get(url);
    }

    if (url.startsWith("file:")) {
        object = load(handleFile(url), option);
        wsdlcache.put(url, object);
        return object;
    } else if (url.startsWith("http:")) {
        log.debug("Getting wsdl component from [" + url + "]");
        //
        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        getMethod = new GetMethod(url);
        client.executeMethod(getMethod);
        byte[] content = getMethod.getResponseBody();
        getMethod.releaseConnection();
        object = load(new ByteArrayInputStream(content), option);
        wsdlcache.put(url, object);
        return object;
    } else {
        return object;
    }
}

From source file:com.fluidops.iwb.api.solution.AbstractSingleFileBasedSolutionService.java

@Override
public List<URI> detectSolutions() {
    File[] handledFiles = detectSolutionFiles();
    if ((handledFiles == null) || (handledFiles.length == 0))
        return null;
    List<URI> uris = Lists.newArrayList();
    for (int f = 0; f < handledFiles.length; f++) {
        File file = handledFiles[f];
        uris.add(file.toURI());
    }/* w w w . j  a  v a2  s  .  c  om*/
    return uris;
}

From source file:com.chiorichan.plugin.loader.PluginClassLoader.java

PluginClassLoader(final JavaPluginLoader loader, final ClassLoader parent,
        final PluginDescriptionFile description, final File dataFolder, final File file)
        throws InvalidPluginException, MalformedURLException {
    super(new URL[] { file.toURI().toURL() }, parent);
    Validate.notNull(loader, "Loader cannot be null");

    this.loader = loader;
    this.description = description;
    this.dataFolder = dataFolder;
    this.file = file;

    try {/*  w ww.ja v a  2s.  c  om*/
        Class<?> jarClass;
        try {
            jarClass = Class.forName(description.getMain(), true, this);
        } catch (ClassNotFoundException ex) {
            throw new InvalidPluginException("Cannot find mane class `" + description.getMain() + "'", ex);
        }

        Class<? extends Plugin> pluginClass;
        try {
            pluginClass = jarClass.asSubclass(Plugin.class);
        } catch (ClassCastException ex) {
            throw new InvalidPluginException(
                    "main class `" + description.getMain() + "' does not extend Plugin", ex);
        }

        plugin = pluginClass.newInstance();
    } catch (IllegalAccessException ex) {
        throw new InvalidPluginException("No public constructor", ex);
    } catch (InstantiationException ex) {
        throw new InvalidPluginException("Abnormal plugin type", ex);
    }
}

From source file:com.intellij.plugins.firstspirit.languagesupport.FirstSpiritClassPathHack.java

public void addFile(UrlClassLoader classLoader, File f) throws Exception {
    System.out.println("Trying to add file " + (f) + " to classpath.");
    addURL(classLoader, f.toURI().toURL());
}