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:ZipURLStreamHandler.java

/**
 * Parses the specified URL string.//from   w ww. j a va2s . c  o  m
 */

protected void parseURL(URL url, String spec, int start, int limit) {
    String urlFile = url.getFile();
    int barIndex = urlFile.indexOf("|");

    String fileName = barIndex == -1 ? urlFile : urlFile.substring(0, barIndex);
    String entryName = barIndex == -1 ? "" : urlFile.substring(barIndex + 1);

    int lastSlashIndex = entryName.lastIndexOf("/");
    String newEntryName = entryName.substring(0, lastSlashIndex + 1) + spec.substring(start, limit);

    setURL(url, url.getProtocol(), "", -1, fileName + "|" + newEntryName, null);
}

From source file:com.constellio.app.modules.es.connectors.http.fetcher.config.BasicUrlNormalizer.java

@Override
public String normalize(String url) throws MalformedURLException, URISyntaxException {
    String trimmedUrl = StringUtils.trim(url);
    String noFragmentUrl = StringUtils.substringBefore(trimmedUrl, "#");
    if (StringUtils.isEmpty(new URL(noFragmentUrl).getFile())) {
        noFragmentUrl = noFragmentUrl + "/";
    }/* w w  w  .  j  a  v a 2s . co m*/
    URL normalizedUrl = new URL(noFragmentUrl);
    String lowerCaseHost = StringUtils.lowerCase(normalizedUrl.getHost());
    normalizedUrl = new URL(normalizedUrl.getProtocol(), lowerCaseHost, normalizedUrl.getPort(),
            normalizedUrl.getFile());
    return normalizedUrl.toURI().normalize().toString();
}

From source file:com.cladonia.xngreditor.URLUtilities.java

/**
 * Convert the given URL to a file.//from w w w .  j a v  a  2s.  c  o  m
 * 
 * @param url the url to be converted.
 * 
 * @return a new file or null if the URL does not describe a file.
 */
public static File toFile(URL url) {
    if (url != null && url.getProtocol().equals("file")) {
        return new File(url.getFile());
    }

    return null;
}

From source file:com.cubusmail.server.services.CubusStartupListener.java

public void contextInitialized(ServletContextEvent servletcontextevent) {

    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletcontextevent.getServletContext());

    try {/*from ww  w  . java 2 s  . com*/
        DBManager dbManager = context.getBean(DBManager.class);
        dbManager.initInternalDB();
    } catch (Exception e) {
        log.fatal(e.getMessage(), e);
        throw new IllegalStateException("Could not initialize internal database!");
    }

    try {
        URL test = CubusStartupListener.class.getClassLoader()
                .getResource(CubusConstants.LOGIN_MODULE_CONFIG_FILE);
        System.setProperty(CubusConstants.JAAS_PROPERTY_NANE, test.getFile());
    } catch (Exception e) {
        log.fatal(e.getMessage(), e);
        throw new IllegalStateException("Could not load " + CubusConstants.LOGIN_MODULE_CONFIG_FILE);
    }
}

From source file:com.cedarsoftware.ncube.NCubeManager.java

private static String getResourceAsString(String name) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream(8192);
    URL url = NCubeManager.class.getResource("/" + name);
    IOUtilities.transfer(new File(url.getFile()), out);
    return new String(out.toByteArray(), "UTF-8");
}

From source file:com.opensoc.test.AbstractSchemaTest.java

protected String readSchemaFromFile(URL schema_url) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader(schema_url.getFile()));
    String line;//from   www.j  a va 2 s  .  c om
    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.linkedin.pinot.queries.BaseMultiValueQueriesTest.java

@BeforeTest
public void buildSegment() throws Exception {
    FileUtils.deleteQuietly(INDEX_DIR);//  w  w  w .  j  a v a  2  s .  co m

    // Get resource file path.
    URL resource = getClass().getClassLoader().getResource(AVRO_DATA);
    Assert.assertNotNull(resource);
    String filePath = resource.getFile();

    // Build the segment schema.
    Schema schema = new Schema.SchemaBuilder().setSchemaName("testTable")
            .addMetric("column1", FieldSpec.DataType.INT).addMetric("column2", FieldSpec.DataType.INT)
            .addSingleValueDimension("column3", FieldSpec.DataType.STRING)
            .addSingleValueDimension("column5", FieldSpec.DataType.STRING)
            .addMultiValueDimension("column6", FieldSpec.DataType.INT)
            .addMultiValueDimension("column7", FieldSpec.DataType.INT)
            .addSingleValueDimension("column8", FieldSpec.DataType.INT)
            .addMetric("column9", FieldSpec.DataType.INT).addMetric("column10", FieldSpec.DataType.INT)
            .addTime("daysSinceEpoch", TimeUnit.DAYS, FieldSpec.DataType.INT).build();

    // Create the segment generator config.
    SegmentGeneratorConfig segmentGeneratorConfig = new SegmentGeneratorConfig(schema);
    segmentGeneratorConfig.setInputFilePath(filePath);
    segmentGeneratorConfig.setTableName("testTable");
    segmentGeneratorConfig.setOutDir(INDEX_DIR.getAbsolutePath());
    segmentGeneratorConfig
            .setInvertedIndexCreationColumns(Arrays.asList("column3", "column7", "column8", "column9"));

    // Build the index segment.
    SegmentIndexCreationDriver driver = new SegmentIndexCreationDriverImpl();
    driver.init(segmentGeneratorConfig);
    driver.build();
}

From source file:de.brendamour.jpasskit.signing.PKInMemorySigningUtilTest.java

@Test
public void testWithInMemoryTemplate() throws JsonParseException, JsonMappingException, IOException,
        URISyntaxException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException,
        KeyStoreException, NoSuchProviderException, PKSigningException {
    PKPassTemplateInMemory pkPassTemplateInMemory = new PKPassTemplateInMemory();

    // icon/*  w w w.  j  a  va 2  s . co  m*/
    URL iconFileURL = PKInMemorySigningUtilTest.class.getClassLoader().getResource("StoreCard.raw/icon@2x.png");
    File iconFile = new File(iconFileURL.getFile());
    pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, iconFile);

    // icon for language
    pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, Locale.ENGLISH, iconFile);

    ObjectMapper jsonObjectMapper = new ObjectMapper();
    PKPass pass = jsonObjectMapper.readValue(new File(getPathFromClasspath("pass2.json")), PKPass.class);

    PKSigningInformation pkSigningInformation = new PKSigningInformationUtil()
            .loadSigningInformationFromPKCS12AndIntermediateCertificate(keyStorePath, keyStorePassword,
                    appleWWDRCA);

    byte[] signedAndZippedPkPassArchive = pkInMemorySigningUtil.createSignedAndZippedPkPassArchive(pass,
            pkPassTemplateInMemory, pkSigningInformation);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(signedAndZippedPkPassArchive);

    File passZipFile = new File("target/passZIPInMemory.zip");
    if (passZipFile.exists()) {
        passZipFile.delete();
    }
    IOUtils.copy(inputStream, new FileOutputStream(passZipFile));
    Assert.assertTrue(passZipFile.exists());
    Assert.assertTrue(passZipFile.length() > 0);
}

From source file:gr.upatras.ece.nam.baker.testclasses.MockRepositoryWebClient.java

@Override
public Path fetchPackageFromLocation(String uuid, String packageLocation) {

    logger.info("TEST fetchMetadata after 2sec from (dummy): " + packageLocation);

    try {/*from w w w  .  j av a  2  s.  c  om*/
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {

        URL res = getClass().getResource(packageLocation);
        logger.info("TEST RESOURCE FILE: " + res);

        File sourceFile = new File(res.getFile());

        Path tempDir = Files.createTempDirectory("baker");
        File destFile = new File(tempDir + "/" + uuid + "/bun.tar.gz");
        Files.createDirectory(Paths.get(tempDir + "/" + uuid));
        Path targetPath = destFile.toPath();

        logger.info(" to:" + targetPath);

        Files.copy(sourceFile.toPath(), targetPath);
        if (mockRepositoryBehavior != MockRepositoryBehavior.RETURN_NULLPACKAGEFILE) {
            return targetPath;
        }

    } catch (IOException e) {

        e.printStackTrace();

    }

    return null;

}

From source file:net.ontopia.utils.ResourcesDirectoryReader.java

private void findResourcesFromFile(URL filePath) {
    findResourcesFromFile(new File(filePath.getFile()), directoryPath);
}