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.citrix.g2w.webdriver.util.FileDownloader.java

public String downloader(String fileToDownloadLocation, String localDownloadPath)
        throws IOException, URISyntaxException {
    URL fileToDownload = new URL(fileToDownloadLocation);
    String fileNameURI = fileToDownload.getFile();
    String filePath = "";
    if (fileNameURI.contains("?")) {
        filePath = localDownloadPath// w w  w  .  j ava  2 s  . c  om
                + fileNameURI.substring(fileNameURI.substring(0, fileNameURI.indexOf("?")).lastIndexOf("/") + 1,
                        fileNameURI.indexOf("?"));
    } else {
        filePath = localDownloadPath + fileNameURI.substring(fileNameURI.lastIndexOf("/") + 1);
    }
    File downloadedFile = new File(filePath);
    if (downloadedFile.canWrite() == false) {
        downloadedFile.setWritable(true);
    }

    HttpClient client = new DefaultHttpClient();
    BasicHttpContext localContext = new BasicHttpContext();

    if (this.mimicWebDriverCookieState) {
        localContext.setAttribute(ClientContext.COOKIE_STORE,
                this.mimicCookieState(this.driver.manage().getCookies()));
    }

    HttpGet httpget = new HttpGet(fileToDownload.toURI());
    HttpParams httpRequestParameters = httpget.getParams();
    httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, this.followRedirects);
    httpget.setParams(httpRequestParameters);

    HttpResponse response = client.execute(httpget, localContext);

    FileUtils.copyInputStreamToFile(response.getEntity().getContent(), downloadedFile);
    response.getEntity().getContent().close();

    String downloadedFileAbsolutePath = downloadedFile.getAbsolutePath();
    this.logger.log("File downloaded to '" + downloadedFileAbsolutePath + "'");

    return downloadedFileAbsolutePath;
}

From source file:com.gemstone.gemfire.internal.logging.log4j.LogWriterLoggerPerformanceTest.java

protected Logger createLogger() throws IOException {
    // create configuration with log-file and log-level
    this.configDirectory = new File(getUniqueName());
    this.configDirectory.mkdir();
    assertTrue(this.configDirectory.isDirectory() && this.configDirectory.canWrite());

    // copy the log4j2-test.xml to the configDirectory
    //final URL srcURL = getClass().getResource("/com/gemstone/gemfire/internal/logging/log4j/log4j2-test.xml");
    final URL srcURL = getClass().getResource("log4j2-test.xml");
    final File src = new File(srcURL.getFile());
    FileUtils.copyFileToDirectory(src, this.configDirectory);
    this.config = new File(this.configDirectory, "log4j2-test.xml");
    assertTrue(this.config.exists());

    this.logFile = new File(this.configDirectory, "gemfire.log");
    final String logFilePath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(logFile);
    final String logFileName = FileUtil.stripOffExtension(logFilePath);
    setPropertySubstitutionValues(logFileName, DEFAULT_LOG_FILE_SIZE_LIMIT, DEFAULT_LOG_FILE_COUNT_LIMIT);

    final String configPath = "file://" + IOUtils.tryGetCanonicalPathElseGetAbsolutePath(this.config);
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configPath);

    final Logger logger = LogWriterLogger.create(this.getClass().getName(), false);
    return logger;
}

From source file:eu.seaclouds.platform.dashboard.model.SeaCloudsApplicationDataStorageTest.java

@BeforeMethod
public void setUp() throws Exception {
    Yaml yamlParser = new Yaml();

    URL resource = Resources.getResource(TOSCA_DAM_FILE_PATH);
    Map toscaDamMap = (Map) yamlParser.load(FileUtils.openInputStream(new File(resource.getFile())));
    // Fill SeaCloudsApplicationDataStorage with empty applications with distinct SeaCloudsID
    for (int i = 0; i < INITIAL_DATASTORE_SIZE; i++) {
        dataStore.addSeaCloudsApplicationData(new SeaCloudsApplicationData(toscaDamMap));
    }/*w w  w.j ava  2  s  .  co m*/
}

From source file:com.gemstone.gemfire.internal.logging.log4j.Log4J2PerformanceTest.java

protected Logger createLogger() throws IOException {
    // create configuration with log-file and log-level
    this.configDirectory = new File(getUniqueName());
    this.configDirectory.mkdir();
    assertTrue(this.configDirectory.isDirectory() && this.configDirectory.canWrite());

    // copy the log4j2-test.xml to the configDirectory
    //final URL srcURL = getClass().getResource("/com/gemstone/gemfire/internal/logging/log4j/log4j2-test.xml");
    final URL srcURL = getClass().getResource("log4j2-test.xml");
    final File src = new File(srcURL.getFile());
    FileUtils.copyFileToDirectory(src, this.configDirectory);
    this.config = new File(this.configDirectory, "log4j2-test.xml");
    assertTrue(this.config.exists());

    this.logFile = new File(this.configDirectory, "gemfire.log");
    final String logFilePath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(logFile);
    final String logFileName = FileUtil.stripOffExtension(logFilePath);
    setPropertySubstitutionValues(logFileName, DEFAULT_LOG_FILE_SIZE_LIMIT, DEFAULT_LOG_FILE_COUNT_LIMIT);

    final String configPath = "file://" + IOUtils.tryGetCanonicalPathElseGetAbsolutePath(this.config);
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configPath);

    final Logger logger = LogManager.getLogger();
    return logger;
}

From source file:ninja.eivind.hotsreplayuploader.providers.hotslogs.HotSLogsProviderTest.java

@Before
public void setUp() throws IOException {
    URL resource = ClassLoader.getSystemClassLoader().getResource("test.StormReplay");
    assertNotNull("Could not load test resource", resource);
    String fileName = resource.getFile();
    parsedReplay = new StormParser().apply(new File(fileName));
    SimpleHttpClient mock = mock(SimpleHttpClient.class);
    when(mock.simpleRequest(anyString())).thenReturn("Duplicate");
    provider.setHttpClient(mock);/*from   w  w w.j  ava 2  s  .  co  m*/
    replayFile = new ReplayFile(new File(fileName));
}

From source file:com.glaf.core.util.ReflectUtils.java

public static String getCodeBase(Class<?> cls) {
    if (cls == null)
        return null;
    ProtectionDomain domain = cls.getProtectionDomain();
    if (domain == null)
        return null;
    CodeSource source = domain.getCodeSource();
    if (source == null)
        return null;
    URL location = source.getLocation();
    if (location == null)
        return null;
    return location.getFile();
}

From source file:com.hortonworks.streamline.streams.service.CustomProcessorUploadHandlerTest.java

@Test
public void testFailures() throws IOException {
    final String[] fileNames = { "nocustomprocessorinfo.tar", "nojarfile.tar", "nocustomprocessorimpl.tar" };
    for (String fileName : fileNames) {
        URL url = classLoader.getResource(resourceDirectoryPrefix + fileName);
        String consoleCustomProcessorTarString = url.getFile();
        File consoleCustomProcessorTar = new File(consoleCustomProcessorTarString);
        FileUtils.copyFileToDirectory(consoleCustomProcessorTar, new File(uploadWatchDirectory), false);
        this.customProcessorUploadHandler.created(Paths.get(uploadWatchDirectory).resolve(fileName));
        File f = new File(failedUploadMoveDirectory + File.separator + fileName);
        Assert.assertTrue(f.exists());//from   w w  w  .  j a  va 2  s. co  m
    }
}

From source file:eu.seaclouds.platform.dashboard.model.SeaCloudsApplicationDataStorageTest.java

@Test
public void testGetSeaCloudsApplicationData() throws Exception {
    Yaml yamlParser = new Yaml();
    URL resource = Resources.getResource(TOSCA_DAM_FILE_PATH);
    Map toscaDamMap = (Map) yamlParser.load(FileUtils.openInputStream(new File(resource.getFile())));

    SeaCloudsApplicationData seaCloudsApplicationData = new SeaCloudsApplicationData(toscaDamMap);
    dataStore.addSeaCloudsApplicationData(seaCloudsApplicationData);

    SeaCloudsApplicationData seaCloudsApplicationDataById = dataStore
            .getSeaCloudsApplicationDataById(seaCloudsApplicationData.getSeaCloudsApplicationId());
    assertEquals(seaCloudsApplicationData, seaCloudsApplicationDataById);
}

From source file:com.hortonworks.streamline.streams.service.CustomProcessorUploadHandlerTest.java

@Test
public void testSuccessfulUpload() throws IOException, ComponentConfigException {
    String fileName = "consolecustomprocessor.tar";
    URL url = classLoader.getResource(resourceDirectoryPrefix + fileName);
    String consoleCustomProcessorTarString = url.getFile();
    File consoleCustomProcessorTar = new File(consoleCustomProcessorTarString);
    FileUtils.copyFileToDirectory(consoleCustomProcessorTar, new File(uploadWatchDirectory), false);
    this.customProcessorUploadHandler.created(Paths.get(uploadWatchDirectory).resolve(fileName));
    new VerificationsInOrder() {
        {// w w w. j  a  v a2 s.  c  om
            InputStream jarFileActual;
            catalogService.addCustomProcessorInfoAsBundle(withEqual(customProcessorInfo),
                    jarFileActual = withCapture());
            times = 1;
            Assert.assertTrue(IOUtils.contentEquals(jarFileActual, jarFile));
        }
    };
}

From source file:eu.delving.test.TestCodeGeneration.java

@Before
public void prep() throws IOException, MetadataException {
    recDefModel.createRecDefTree(new SchemaVersion("test", "0.0.0"));
    URL mappingResource = getClass().getResource("/codegen/TestCodeGeneration-mapping.xml");
    recMapping = RecMapping.read(new File(mappingResource.getFile()), recDefModel);
    recMapping.getRecDefTree().setListener(new ChattyListener());
    URL inputResource = getClass().getResource("/codegen/TestCodeGeneration-input.xml");
    input = FileUtils.readFileToString(new File(inputResource.getFile()));
    URL expectResource = getClass().getResource("/codegen/TestCodeGeneration-expect.xml");
    expect = FileUtils.readFileToString(new File(expectResource.getFile()));
}