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:eu.diacron.crawlservice.app.Util.java

private static String getwarcByURL(String warcURLasString) {
    File warcfile = null;/*from   www.  j  ava 2s.  c o  m*/
    try {
        URL warcURL = new URL(warcURLasString);
        String fileName = FilenameUtils.getBaseName(warcURLasString);

        warcfile = new File(Configuration.TMP_FOLDER_CRAWL + fileName + ".gz");
        FileUtils.copyURLToFile(warcURL, warcfile);
    } catch (IOException ex) {
        Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println("warcfile.getAbsolutePath() " + warcfile.getAbsolutePath());
    return warcfile.getAbsolutePath();

}

From source file:net.openbyte.gui.CreateProjectFrame.java

private void cloneAPI() {
    if (this.api == ModificationAPI.MINECRAFT_FORGE) {
        String link;//w  w w .j  a v  a 2  s  . c o  m
        if (this.version == MinecraftVersion.BOUNTIFUL_UPDATE) {
            // too old -> link = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/1.8.9-11.15.0.1684/forge-1.8.9-11.15.0.1684-mdk.zip";
            link = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/1.8.9-11.15.1.1722/forge-1.8.9-11.15.1.1722-mdk.zip";
        } else {
            link = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/1.7.10-10.13.4.1614-1.7.10/forge-1.7.10-10.13.4.1614-1.7.10-src.zip";
        }
        File forgeZip = new File(projectFolder, "forge.zip");
        try {
            URL url = new URL(link);
            FileUtils.copyURLToFile(url, forgeZip);
            ZipFile zipFile = new ZipFile(forgeZip);
            zipFile.extractAll(projectFolder.getAbsolutePath());
            forgeZip.delete();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (this.api == ModificationAPI.MCP) {
        String link = "http://maven.torchpowered.gq/mcp_releases/mcp924.zip";
        ;
        if (this.version == MinecraftVersion.BOUNTIFUL_UPDATE) {
            link = "http://www.modcoderpack.com/website/sites/default/files/releases/mcp918.zip";
        }
        if (this.version == MinecraftVersion.THE_UPDATE_THAT_CHANGED_THE_WORLD) {
            link = "http://www.modcoderpack.com/website/sites/default/files/releases/mcp908.zip";
        }
        File mcpZip = new File(projectFolder, "mcp.zip");
        try {
            URL url = new URL(link);
            FileUtils.copyURLToFile(url, mcpZip);
            ZipFile zipFile = new ZipFile(mcpZip);
            zipFile.extractAll(projectFolder.getAbsolutePath());
            mcpZip.delete();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (this.api == ModificationAPI.BUKKIT) {
        String link = "http://maven.torchpowered.gq/org/bukkit/1.9-R0.1-SNAPSHOT/Bukkit-1.9-R0.1-SNAPSHOT.jar";
        File apiFolder = new File(projectFolder, "api");
        apiFolder.mkdirs();
        File apiJar = new File(apiFolder, "bukkit.jar");
        try {
            URL url = new URL(link);
            FileUtils.copyURLToFile(url, apiJar);
        } catch (Exception e) {
            e.printStackTrace();
        }
        File src = new File(projectFolder, "src");
        File main = new File(src, "main");
        File java = new File(main, "java");
        File resources = new File(main, "resources");
        src.mkdir();
        main.mkdir();
        java.mkdir();
        resources.mkdir();
    }
}

From source file:com.thoughtworks.go.plugin.infra.listeners.DefaultPluginJarChangeListener.java

void installActivatorJarToBundleDir(File pluginBundleExplodedDir) {
    URL activatorJar = findAndValidateActivatorJar();
    File pluginActivatorJarDestination = new File(
            new File(pluginBundleExplodedDir, GoPluginOSGiManifest.PLUGIN_DEPENDENCY_DIR), ACTIVATOR_JAR_NAME);

    try {//  w w w . ja  v  a 2  s  .co m
        FileUtils.copyURLToFile(activatorJar, pluginActivatorJarDestination);
    } catch (IOException e) {
        throw new RuntimeException(String.format("Failed to copy activator jar %s to bundle dependency dir: %s",
                activatorJar, pluginActivatorJarDestination), e);
    }
}

From source file:dk.nsi.sdm4.ydelse.parser.YdelseparserTest.java

private File makeDatadirWithResource(String path) throws IOException {
    File datasetDir = tmpDir.newFolder();
    URL url = this.getClass().getResource(path);
    FileUtils.copyURLToFile(url, new File(datasetDir, "testfile.csv"));

    return datasetDir;
}

From source file:com.github.blindpirate.gogradle.util.IOUtils.java

public static void copyURLToFile(URL url, File dest) {
    try {// w  ww  .j a v a 2s .co m
        FileUtils.copyURLToFile(url, dest);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:api.wiki.WikiNameApi2.java

private File processName(String name, PeopleNameOption option) {
    final String url = "http://en.wikipedia.org/w/api.php?format=xml&action=query&titles="
            + name.replaceAll("\\s+", "_") + "&prop=links&pllimit=500&plnamespace=0";
    File file = null;//  w  ww.j a  va 2  s  .co m
    try {
        file = File.createTempFile(option.genre.toUpperCase() + "_" + name + "_", option.gender.name(),
                new File("/temp"));
        URL u = new URL(url);
        FileUtils.copyURLToFile(u, file);

    } catch (IOException ex) {
        Logger.getLogger(WikiNameApi2.class.getName()).log(Level.SEVERE, null, ex);
    }
    return file;
}

From source file:edu.duke.cabig.c3pr.webservice.integration.C3PREmbeddedTomcatTestBase.java

/**
 * Starts c3pr in embedded Tomcat./* w  w  w .j  a  va  2  s .  com*/
 * 
 * @throws LifecycleException
 * @throws IOException
 */
private void startTomcat() throws LifecycleException, IOException {
    logger.info("Starting Tomcat...");

    File defaultWebXml = new File(tmpDir, WEB_XML_FILENAME);
    FileUtils.copyURLToFile(C3PREmbeddedTomcatTestBase.class.getResource(TESTDATA + "/" + WEB_XML_FILENAME),
            defaultWebXml);

    final File rootContextDir = new File(webappsDir, ROOT);
    rootContextDir.mkdir();

    container = new Embedded();
    container.setCatalinaHome(catalinaHome.getCanonicalPath());

    Engine engine = container.createEngine();
    engine.setName("TestEngine");

    Host localHost = container.createHost("localhost", webappsDir.getCanonicalPath());
    localHost.setDeployOnStartup(true);
    localHost.setAutoDeploy(true);
    engine.setDefaultHost(localHost.getName());
    engine.addChild(localHost);

    StandardContext rootContext = (StandardContext) container.createContext("",
            rootContextDir.getAbsolutePath());
    rootContext.setReloadable(false);
    rootContext.setDefaultWebXml(defaultWebXml.getCanonicalPath());

    StandardContext context = (StandardContext) container.createContext(C3PR_CONTEXT,
            warFile.getAbsolutePath());
    context.setReloadable(false);
    context.setDefaultWebXml(defaultWebXml.getCanonicalPath());

    localHost.addChild(rootContext);
    localHost.addChild(context);

    container.addEngine(engine);

    Connector httpConnector = container.createConnector((InetAddress) null, port, false);
    httpConnector.setRedirectPort(sslPort);

    Connector httpsConnector = container.createConnector((InetAddress) null, sslPort, true);
    httpsConnector.setScheme("https");
    httpsConnector.setProperty("keystoreFile", tomcatKeystore.getCanonicalPath());

    container.addConnector(httpConnector);
    container.addConnector(httpsConnector);
    container.setAwait(true);

    // start server
    container.start();
    logger.info("Tomcat has been started.");
}

From source file:com.anritsu.mcreleaseportal.tcintegration.ProcessTCRequest.java

public Result saveChangesXML(String changesXMLFileName) {
    try {//from   w ww  .ja  va  2s.c  o  m
        File tempFile = File.createTempFile(changesXMLFileName, "changes.xml");
        String changesXMLUrl = artifactsLocation + "/" + changesXMLFileName;
        System.out.println("Downloading " + changesXMLUrl);
        FileUtils.copyURLToFile(new URL(changesXMLUrl), tempFile);

        Path source = Paths.get((String) tempFile.getAbsolutePath());
        new File(new File("").getAbsolutePath() + "/" + Configuration.getInstance().getSavePath() + "/"
                + mcPackage.getPackageName()).mkdirs();
        Path destination = Paths.get(new File("").getAbsolutePath() + "/"
                + Configuration.getInstance().getSavePath() + "/" + mcPackage.getPackageName() + "/"
                + changesXMLFileName + "_" + mcPackage.getStatus() + "_" + System.currentTimeMillis());

        Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING);
        System.out.println(source.toString() + " renamed to " + destination.toAbsolutePath().toString());
        result.setResultMessage(destination.toAbsolutePath().toString());

    } catch (IOException ex) {
        Logger.getLogger(ProcessTCRequest.class.getName()).log(Level.SEVERE, null, ex);
        result.setResultCode("1");
        result.setResultMessage(ex.getMessage());
    }
    return result;
}

From source file:Data.c_CardDB.java

public c_Card getCard(Integer mid) {
    if (contains(mid)) {
        return m_cards.get(mid);
    } else {/*w  ww  . j av  a 2s  .co  m*/
        c_Card card = new c_Card();

        try {
            File tempFile = File.createTempFile("phils_deck_builder", null);
            c_File file = new c_File();
            ArrayList<String> content;

            FileUtils.copyURLToFile(new URL(
                    String.format("http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=%s", mid)),
                    tempFile);
            content = file.read(tempFile.getCanonicalPath(), false);
            WebBrowserPanel.parseContent(content, card);
            tempFile.deleteOnExit();

            tempFile = null;
            file = null;
            content = null;
        } catch (Exception ex2) {
            int i = 0;
        }

        return card;
    }
}

From source file:ffx.numerics.fft.Complex3DCuda.java

/**
 * {@inheritDoc}// w  w w .  ja va  2s . co m
 */
@Override
public void run() {
    JCudaDriver.setExceptionsEnabled(true);
    JCufft.setExceptionsEnabled(true);
    JCudaDriver.setLogLevel(LogLevel.LOG_INFO);
    JCufft.setLogLevel(LogLevel.LOG_INFO);
    JCufft.initialize();

    // Initialize the driver and create a context for the first device.
    cuInit(0);
    CUcontext pctx = new CUcontext();
    CUdevice dev = new CUdevice();
    CUdevprop prop = new CUdevprop();
    cuDeviceGetProperties(prop, dev);
    logger.log(Level.INFO, "   CUDA {0}", prop.toFormattedString());
    cuDeviceGet(dev, 0);

    // Create a context that allows the GPU to map pinned host memory.
    if (usePinnedMemory) {
        cuCtxCreate(pctx, CUctx_flags.CU_CTX_MAP_HOST, dev);
    } else {
        // Create a context that does not allows the GPU to map pinned host memory.
        cuCtxCreate(pctx, 0, dev);
    }

    // Load the CUBIN file and obtain the "recipSummation" function.
    try {
        String bit = System.getProperty("sun.arch.data.model").trim();
        URL source = getClass().getClassLoader()
                .getResource("ffx/numerics/fft/recipSummation-" + bit + ".cubin");
        File cubinFile = File.createTempFile("recipSummation", "cubin");
        FileUtils.copyURLToFile(source, cubinFile);
        module = new CUmodule();
        cuModuleLoad(module, cubinFile.getCanonicalPath());
        function = new CUfunction();
        cuModuleGetFunction(function, module, "recipSummation");
    } catch (Exception e) {
        String message = " Error loading the reciprocal summation kernel";
        logger.log(Level.SEVERE, message, e);
    }

    pinnedMemory = new Pointer();

    if (usePinnedMemory) {
        // Allocate pinned memory mapped into the GPU address space.
        cuMemHostAlloc(pinnedMemory, len * 2 * Sizeof.DOUBLE, CU_MEMHOSTALLOC_DEVICEMAP);
    } else {
        // Allocate memory
        cuMemHostAlloc(pinnedMemory, len * 2 * Sizeof.DOUBLE, 0);
    }

    ByteBuffer byteBuffer = pinnedMemory.getByteBuffer(0, len * 2 * Sizeof.DOUBLE);
    byteBuffer.order(ByteOrder.nativeOrder());
    pinnedMemoryBuffer = byteBuffer.asDoubleBuffer();

    // Allocate a work array on the device.
    dataDevice = new CUdeviceptr();
    cuMemAlloc(dataDevice, len * 2 * Sizeof.DOUBLE);

    // Allocate memory on the device for the reciprocal space array.
    recipDevice = new CUdeviceptr();
    cuMemAlloc(recipDevice, len * Sizeof.DOUBLE);

    // Create and execute a JCufft plan for the data
    plan = new cufftHandle();

    cufftPlan3d(plan, nZ, nY, nX, cufftType.CUFFT_Z2Z);
    //cufftSetCompatibilityMode(plan, cufftCompatibility.CUFFT_COMPATIBILITY_FFTW_ALL);

    dataGPUPtr = Pointer.to(dataDevice);
    recipGPUPtr = Pointer.to(recipDevice);

    int threads = prop.maxThreadsPerBlock;
    int nBlocks = len / threads + (len % threads == 0 ? 0 : 1);
    int gridSize = (int) Math.floor(Math.sqrt(nBlocks)) + 1;

    logger.info(format("   CUDA thread initialized: %d threads per block", threads));
    logger.info(format("   Grid Size:                     (%3d,%3d,%3d)", gridSize, gridSize, 1));

    assert (gridSize * gridSize * threads >= len);

    synchronized (this) {
        while (!free) {
            if (mode != null) {
                switch (mode) {

                case RECIP:
                    cuMemcpyHtoD(recipDevice, recipCPUPtr, len * Sizeof.DOUBLE);
                    break;

                case FFT:
                    // Zero Copy
                    if (usePinnedMemory) {
                        cufftExecZ2Z(plan, pinnedMemory, pinnedMemory, CUFFT_FORWARD);
                    } else {
                        cuMemcpyHtoD(dataDevice, pinnedMemory, 2 * len * Sizeof.DOUBLE);
                        cufftExecZ2Z(plan, dataDevice, dataDevice, CUFFT_FORWARD);
                        cuMemcpyDtoH(pinnedMemory, dataDevice, 2 * len * Sizeof.DOUBLE);
                    }
                    break;

                case CONVOLUTION:

                    if (usePinnedMemory) {
                        // Zero Copy
                        cufftExecZ2Z(plan, pinnedMemory, dataDevice, CUFFT_FORWARD);
                    } else {
                        // Copy data to device and run forward FFT.
                        cuMemcpyHtoD(dataDevice, pinnedMemory, 2 * len * Sizeof.DOUBLE);
                        cufftExecZ2Z(plan, dataDevice, dataDevice, CUFFT_FORWARD);
                    }

                    // Set up the execution parameters for the kernel
                    cuFuncSetBlockShape(function, threads, 1, 1);
                    int offset = 0;
                    offset = align(offset, Sizeof.POINTER);
                    cuParamSetv(function, offset, dataGPUPtr, Sizeof.POINTER);
                    offset += Sizeof.POINTER;
                    offset = align(offset, Sizeof.POINTER);
                    cuParamSetv(function, offset, recipGPUPtr, Sizeof.POINTER);
                    offset += Sizeof.POINTER;
                    offset = align(offset, Sizeof.INT);
                    cuParamSeti(function, offset, len);
                    offset += Sizeof.INT;
                    cuParamSetSize(function, offset);
                    // Call the kernel function.
                    cuLaunchGrid(function, gridSize, gridSize);
                    if (usePinnedMemory) {
                        // Zero Copy
                        cufftExecZ2Z(plan, dataDevice, pinnedMemory, CUFFT_INVERSE);
                    } else {
                        // Perform inverse FFT and copy memory back to the CPU.
                        cufftExecZ2Z(plan, dataDevice, dataDevice, CUFFT_INVERSE);
                        cuMemcpyDtoH(pinnedMemory, dataDevice, 2 * len * Sizeof.DOUBLE);
                    }
                    break;

                case IFFT:
                    // Zero Copy
                    if (usePinnedMemory) {
                        cufftExecZ2Z(plan, pinnedMemory, pinnedMemory, CUFFT_INVERSE);
                    } else {
                        cuMemcpyHtoD(dataDevice, pinnedMemory, 2 * len * Sizeof.DOUBLE);
                        cufftExecZ2Z(plan, dataDevice, dataDevice, CUFFT_INVERSE);
                        cuMemcpyDtoH(pinnedMemory, dataDevice, 2 * len * Sizeof.DOUBLE);
                    }
                    break;
                }

                // Block for the context's tasks to complete.
                cuCtxSynchronize();

                // Reset the mode to null and notify the calling thread.
                mode = null;
                notify();
            }
            // The CUDA thread will wait until it's notified again.
            try {
                wait();
            } catch (InterruptedException e) {
                logger.severe(e.toString());
            }
        }
        cufftDestroy(plan);
        cuMemFree(dataDevice);
        cuMemFree(recipDevice);
        cuMemFreeHost(pinnedMemory);
        dead = true;
        notify();
    }
    logger.info(" CUDA Thread Done!");
}