Example usage for org.apache.commons.io FileUtils copyURLToFile

List of usage examples for org.apache.commons.io FileUtils copyURLToFile

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils copyURLToFile.

Prototype

public static void copyURLToFile(URL source, File destination) throws IOException 

Source Link

Document

Copies bytes from the URL source to a file destination.

Usage

From source file:org.geowebcache.config.ServerConfigurationTest.java

protected ServerConfiguration getConfig() throws Exception {
    if (configFile == null) {
        // create a temp XML config
        configDir = temp.getRoot();// w  w w .  j a v  a2s.c  o  m
        configFile = temp.newFile(XMLConfiguration.DEFAULT_CONFIGURATION_FILE_NAME);
        // copy the example XML to the temp config file
        URL source = XMLConfiguration.class.getResource("geowebcache_190.xml");
        FileUtils.copyURLToFile(source, configFile);
    }
    // initialize the config with an XMLFileResourceProvider that uses the temp config file
    gridSetBroker = new GridSetBroker(true, true);
    ConfigurationResourceProvider configProvider = new XMLFileResourceProvider(
            XMLConfiguration.DEFAULT_CONFIGURATION_FILE_NAME, (WebApplicationContext) null,
            configDir.getAbsolutePath(), null);
    config = new XMLConfiguration(null, configProvider);
    ((XMLConfiguration) config).setGridSetBroker(gridSetBroker);
    config.afterPropertiesSet();
    return config;
}

From source file:org.geowebcache.config.XMLConfigurationBlobStoreConformanceTest.java

protected void makeConfigFile() throws IOException {
    if (configFile == null) {
        configDir = temp.getRoot();//from   ww w .j av  a2  s  .  com
        configFile = temp.newFile("geowebcache.xml");

        URL source = XMLConfiguration.class.getResource("geowebcache_190.xml");
        FileUtils.copyURLToFile(source, configFile);
    }
}

From source file:org.geowebcache.config.XMLConfigurationGridsetConformanceTest.java

protected void makeConfigFile() throws IOException {
    if (configFile == null) {
        configDir = temp.getRoot();//from   ww  w  .  j a  v a 2  s . co m
        configFile = temp.newFile("geowebcache.xml");

        URL source = XMLConfiguration.class
                .getResource(XMLConfigurationBackwardsCompatibilityTest.LATEST_FILENAME);
        FileUtils.copyURLToFile(source, configFile);
    }
}

From source file:org.geowebcache.config.XMLConfigurationLayerConformanceTest.java

protected void makeConfigFile() throws Exception {
    if (configFile == null) {
        configDir = temp.getRoot();/*from ww w .j a  va  2 s  .c  o m*/
        configFile = temp.newFile("geowebcache.xml");

        URL source = XMLConfiguration.class.getResource("geowebcache_1120.xml");
        FileUtils.copyURLToFile(source, configFile);
    }
}

From source file:org.giggsoff.jspritproj.utils.GraphhopperWorker.java

public GraphhopperWorker(String osmFile, String graphFolder) throws MalformedURLException, IOException {
    File fl = new File(osmFile);
    if (!fl.exists()) {
        FileUtils.copyURLToFile(
                new URL("http://download.geofabrik.de/russia/northwestern-fed-district-latest.osm.pbf"), fl);
    }//ww  w.j  av  a2  s  . c  o m
    hopper.setDataReaderFile(fl.getPath());
    // where to store graphhopper files?
    hopper.setGraphHopperLocation(graphFolder);
    hopper.setEncodingManager(new EncodingManager("car"));
    hopper.setElevation(true);
    hopper.setElevationProvider(new SRTMProvider());

    // now this can take minutes if it imports or a few seconds for loading
    // of course this is dependent on the area you import
    hopper.importOrLoad();
}

From source file:org.gradle.util.GFileUtils.java

public static void copyURLToFile(URL source, File destination) {
    try {//from  w  ww.  ja va2s .  com
        FileUtils.copyURLToFile(source, destination);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.gradle.util.TestFile.java

public void copyFrom(URL resource) {
    try {/*from  w  w w  . ja v a 2s .co m*/
        FileUtils.copyURLToFile(resource, this);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.iexhub.services.CreateApplicationMapService.java

@POST
@Produces("application/xml")
public Response createApplicationMap(@QueryParam("applicationId") String applicationId,
        @QueryParam("referentIndex") String referentIndex, @QueryParam("mappingFile") String mappingFile) {
    try {/*from  w ww  .  ja  v  a2 s .c  om*/
        File destinationRootDir = new File(testOutputPath);

        // mappingFile may be either the XML mapping itself or a URI pointing to a file containing the XML mapping.  To test
        //   for the URI, try to construct a URI object...
        try {
            URL test = new URL(mappingFile);

            // We have a URI - copy the file...
            try {
                FileUtils.copyURLToFile(test, new File(destinationRootDir, applicationId + "Map.xmi"));
            } catch (IOException ex) {
                throw new URLToMapFileCopyException(
                        "Error encountered while copying URL to map file, info=" + ex.getMessage());
            }
        } catch (MalformedURLException ex) {
            // Mapping is in the mappingFile parameter - serialize it to a file...
            File destinationFile = new File(destinationRootDir, applicationId + "Map.xmi");

            try {
                Files.write(Paths.get(destinationFile.getAbsolutePath()), mappingFile.getBytes());
            } catch (IOException ex2) {
                throw new MapFileCreationException(
                        "Error encountered while creating map file, info=" + ex.getMessage());
            }
        }
    } catch (URLToMapFileCopyException | MapFileCreationException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new UnexpectedServerException("Error - " + ex.getMessage());
    }

    return Response.status(Response.Status.OK).build();
}

From source file:org.jamwiki.utils.Utilities.java

/**
 * Given a file name for a file that is located somewhere in the application
 * classpath, return a File object representing the file.
 *
 * @param filename The name of the file (relative to the classpath) that is
 *  to be retrieved./*  www.  j  a  v a2s  .c  o  m*/
 * @return A file object representing the requested filename
 * @throws FileNotFoundException Thrown if the classloader can not be found or if
 *  the file can not be found in the classpath.
 */
public static File getClassLoaderFile(String filename) throws FileNotFoundException {
    // note that this method is used when initializing logging, so it must
    // not attempt to log anything.
    File file = null;
    ClassLoader loader = Utilities.getClassLoader();
    URL url = loader.getResource(filename);
    if (url == null) {
        url = ClassLoader.getSystemResource(filename);
    }
    if (url == null) {
        throw new FileNotFoundException("Unable to find " + filename);
    }
    file = FileUtils.toFile(url);
    if (file == null || !file.exists()) {
        try {
            // url exists but file cannot be read, so perhaps it's not a "file:" url (an example
            // would be a "jar:" url).  as a workaround, copy the file to a temp file and return
            // the temp file.
            file = File.createTempFile(filename, null);
            FileUtils.copyURLToFile(url, file);
        } catch (IOException e) {
            throw new FileNotFoundException("Unable to load file with URL " + url);
        }
    }
    return file;
}

From source file:org.jbb.lib.cache.hazelcast.HazelcastConfigFilesManager.java

private void copyFromClasspath(String classpathFileName) {

    ClassPathResource classPathResource = new ClassPathResource(classpathFileName);
    File targetFile = new File(jbbMetaData.jbbConfigDirectory() + File.separator + classpathFileName);
    try {//from www .  j av a 2 s .  c  o  m
        if (!targetFile.exists()) {
            FileUtils.copyURLToFile(classPathResource.getURL(), targetFile);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}