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:com.opensoc.test.AbstractConfigTest.java

protected String readSchemaFromFile(URL schema_url) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader(schema_url.getFile()));
    String line;/*  w  ww. ja va2s  .  c o  m*/
    StringBuilder sb = new StringBuilder();
    while ((line = br.readLine()) != null) {
        System.out.println(line);
        sb.append(line);
    }
    br.close();

    String schema_string = sb.toString().replaceAll("\n", "");
    schema_string = schema_string.replaceAll(" ", "");

    System.out.println("Read in schema: " + schema_string);

    return schema_string;
}

From source file:com.joliciel.jochre.JochreServiceLocator.java

private Properties getDataSourceProperties() {
    if (dataSourceProperties == null
            && (this.getDataSourcePropertiesResource() != null || this.getDataSourcePropertiesFile() != null)) {
        dataSourceProperties = new Properties();
        try {//from  ww w  .  j a v a  2s.  co  m
            String filePath = null;
            if (this.getDataSourcePropertiesFile() != null) {
                filePath = this.getDataSourcePropertiesFile();
            } else if (this.getDataSourcePropertiesResource() != null) {
                LOG.debug("Loading database properties from: " + this.getDataSourcePropertiesResource());
                URL url = ClassLoader.getSystemResource(this.getDataSourcePropertiesResource());
                filePath = url.getFile();
            }
            FileInputStream fis = new FileInputStream(filePath);
            dataSourceProperties.load(fis);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    return dataSourceProperties;
}

From source file:com.ning.billing.beatrix.osgi.SetupBundleWithAssertion.java

private void installJrubyJar() throws IOException {

    final String resourceName = JRUBY_BUNDLE_RESOURCE + "-" + killbillVersion + ".jar";
    final URL resourceUrl = Resources.getResource(resourceName);
    final File rubyJarInput = new File(resourceUrl.getFile());

    final File platform = new File(rootInstallDir, "platform");
    if (!platform.exists()) {
        platform.mkdir();/*from w w  w.j  a  v  a2 s  .  com*/
    }

    final File rubyJarDestination = new File(platform, "jruby.jar");
    ByteStreams.copy(new FileInputStream(rubyJarInput), new FileOutputStream(rubyJarDestination));
}

From source file:fr.gael.dhus.owcclient.OwcClientWebapp.java

@Override
public void configure(String dest_folder) throws IOException {
    String configurationFolder = "fr/gael/dhus/owcclient";
    URL u = Thread.currentThread().getContextClassLoader().getResource(configurationFolder);
    if (u != null && "jar".equals(u.getProtocol())) {
        extractJarFolder(u, configurationFolder, dest_folder);
    } else if (u != null) {
        File webAppFolder = new File(dest_folder);
        copyFolder(new File(u.getFile()), webAppFolder);
    }//from  w  w  w.  ja va2  s  . com

}

From source file:ch.epfl.leb.sass.models.fluorophores.commands.internal.FluorophoreReceiverIT.java

/**
 * Test of generateFluorophoresFromCSV method, of class FluorophoreReceiver.
 */// w w  w. j  a  va2s.  c  om
@Test
public void testGenerateFluorophoresFromCSV() throws Exception {
    URL csv = FluorophoreReceiverIT.class.getResource("/label_pix_sass.csv");
    File csvFile = new File(csv.getFile());
    GenerateFluorophoresFromCSV.Builder fluorBuilder = new GenerateFluorophoresFromCSV.Builder();
    fluorBuilder.file(csvFile); // The file containing the locations.
    fluorBuilder.rescale(true); // Rescale positions to fit image?

    // Create the set of fluorophores.
    fluorBuilder.camera(camera).psfBuilder(psfBuilder).fluorDynamics(fluorDynamics).illumination(illumination);
    FluorophoreCommand fluorCommand = fluorBuilder.build();
    List<Fluorophore> fluorophores = fluorCommand.generateFluorophores();
    assertEquals(69358, fluorophores.size());

    double minX = Double.POSITIVE_INFINITY;
    double maxX = Double.NEGATIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY;
    double maxY = Double.NEGATIVE_INFINITY;
    for (Fluorophore f : fluorophores) {
        if (f.getX() < minX)
            minX = f.getX();

        if (f.getX() > maxX)
            maxX = f.getX();

        if (f.getY() < minY)
            minY = f.getY();

        if (f.getY() > maxY)
            maxY = f.getY();
    }

    assertTrue(maxX <= 32);
    assertTrue(minX >= 0.0);
    assertTrue(maxY <= 32);
    assertTrue(minY >= 0.0);
}

From source file:co.cask.hydrator.plugin.batch.action.FileActionTestRun.java

/**
 * Method to copy test xml files into source folder path, from where test case read the file.
 *///from  w  w  w . j  ava  2s . c  o  m
@Before
public void copyFiles() throws IOException {
    URL largeXMLUrl = this.getClass().getResource("/" + CATALOG_LARGE_XML_FILE_NAME);
    URL smallXMLUrl = this.getClass().getResource("/" + CATALOG_SMALL_XML_FILE_NAME);
    FileUtils.copyFile(new File(largeXMLUrl.getFile()), new File(sourceFolder, CATALOG_LARGE_XML_FILE_NAME));
    FileUtils.copyFile(new File(smallXMLUrl.getFile()), new File(sourceFolder, CATALOG_SMALL_XML_FILE_NAME));
}

From source file:lumbermill.aws.lambda.LambdaWithConfig.java

private synchronized JsonNode node() {
    if (node == null) {
        URL resource = Thread.currentThread().getContextClassLoader().getResource(configFile);

        if (resource == null) {
            throw new IllegalStateException("Failed to find file: " + configFile);
        }/* ww  w  .  ja  v a  2 s .  c o  m*/

        try {
            this.node = Json.OBJECT_MAPPER.readValue(new File(resource.getFile()), JsonNode.class);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }

        LOGGER.info("Loaded configuration file: {}", configFile);
    }
    return node;
}

From source file:hk.hku.cecid.corvus.http.HttpSenderUnitTest.java

/** Initialize the test target which is a HTTP Sender. */
public void initTestTarget() throws Exception {
    URL logURL = FIXTURE_LOADER.getResource(TEST_LOG);
    if (logURL == null)
        throw new NullPointerException("Missing fixture " + TEST_LOG + " in the fixture path");

    File log = new File(logURL.getFile());
    this.testClassLogger = new FileLogger(log);
    this.target = new HttpSender(this.testClassLogger, new KVPairData(0));
    this.target.setServiceEndPoint(TEST_ENDPOINT);
}

From source file:com.iflytek.spider.net.BasicURLNormalizer.java

public String normalize(String urlString) throws MalformedURLException {
    if ("".equals(urlString)) // permit empty
        return urlString;

    urlString = urlString.trim(); // remove extra spaces

    URL url = new URL(urlString);

    String protocol = url.getProtocol();
    String host = url.getHost();/*from w  w  w.ja  va 2s.  c  o  m*/
    int port = url.getPort();
    String file = url.getFile();

    boolean changed = false;

    if (!urlString.startsWith(protocol)) // protocol was lowercased
        changed = true;

    if ("http".equals(protocol) || "ftp".equals(protocol)) {

        if (host != null) {
            String newHost = host.toLowerCase(); // lowercase host
            if (!host.equals(newHost)) {
                host = newHost;
                changed = true;
            }
        }

        if (port == url.getDefaultPort()) { // uses default port
            port = -1; // so don't specify it
            changed = true;
        }

        if (file == null || "".equals(file)) { // add a slash
            file = "/";
            changed = true;
        }

        if (url.getRef() != null) { // remove the ref
            changed = true;
        }

        // check for unnecessary use of "/../"
        String file2 = substituteUnnecessaryRelativePaths(file);

        if (!file.equals(file2)) {
            changed = true;
            file = file2;
        }

    }

    if (changed)
        urlString = new URL(protocol, host, port, file).toString();

    return urlString;
}

From source file:com.phonegap.plugin.files.ExtractZipFilePlugin.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext cbc) {
    PluginResult.Status status = PluginResult.Status.OK;
    try {//  www. j  av  a  2 s.  c o  m
        String filename = args.getString(0);
        URL url;
        try {
            url = new URL(filename);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        File file = new File(url.getFile());
        String[] dirToSplit = url.getFile().split(File.separator);
        String dirToInsert = "";
        for (int i = 0; i < dirToSplit.length - 1; i++) {
            dirToInsert += dirToSplit[i] + File.separator;
        }

        ZipEntry entry;
        ZipFile zipfile;
        try {
            zipfile = new ZipFile(file);
            Enumeration e = zipfile.entries();
            while (e.hasMoreElements()) {
                entry = (ZipEntry) e.nextElement();
                BufferedInputStream is = null;
                try {
                    is = new BufferedInputStream(zipfile.getInputStream(entry));
                    int count;
                    byte data[] = new byte[102222];
                    String fileName = dirToInsert + entry.getName();
                    File outFile = new File(fileName);
                    if (entry.isDirectory()) {
                        if (!outFile.exists() && !outFile.mkdirs()) {
                            Log.v("info", "Unable to create directories: " + outFile.getAbsolutePath());
                            cbc.sendPluginResult(new PluginResult(IO_EXCEPTION));
                            return false;
                        }
                    } else {
                        File parent = outFile.getParentFile();
                        if (parent.mkdirs()) {
                            Log.v("info", "created directory leading to file");
                        }
                        FileOutputStream fos = null;
                        BufferedOutputStream dest = null;
                        try {
                            fos = new FileOutputStream(outFile);
                            dest = new BufferedOutputStream(fos, 102222);
                            while ((count = is.read(data, 0, 102222)) != -1) {
                                dest.write(data, 0, count);
                            }
                        } finally {
                            if (dest != null) {
                                dest.flush();
                                dest.close();
                            }
                            if (fos != null) {
                                fos.close();
                            }
                        }
                    }
                } finally {
                    if (is != null) {
                        is.close();
                    }
                }
            }
        } catch (ZipException e1) {
            Log.v("error", e1.getMessage(), e1);
            cbc.sendPluginResult(new PluginResult(MALFORMED_URL_EXCEPTION));
            return false;
        } catch (IOException e1) {
            Log.v("error", e1.getMessage(), e1);
            cbc.sendPluginResult(new PluginResult(IO_EXCEPTION));
            return false;
        }

    } catch (JSONException e) {
        cbc.sendPluginResult(new PluginResult(JSON_EXCEPTION));
        return false;
    }
    cbc.sendPluginResult(new PluginResult(status));
    return true;
}