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

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

Introduction

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

Prototype

public static void forceDelete(File file) throws IOException 

Source Link

Document

Deletes a file.

Usage

From source file:edu.ucsb.eucalyptus.storage.fs.FileSystemStorageManager.java

public void renameObject(String bucket, String oldName, String newName) throws IOException {
    File oldObjectFile = new File(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + oldName);
    File newObjectFile = new File(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + newName);
    if (oldObjectFile.exists()) {
        FileUtils.forceDelete(oldObjectFile);
        FileUtils.moveFile(oldObjectFile, newObjectFile);
        //         newObjectFile.delete();
        //         if (!oldObjectFile.renameTo(newObjectFile)) {
        //            throw new IOException("Unable to rename " + oldObjectFile.getAbsolutePath() + " to "
        //                  + newObjectFile.getAbsolutePath());
        //         }
    }/*w w  w  .  j  av a 2  s  . co m*/
}

From source file:Forms.CreateGearForm.java

private Boolean saveSpec(GearSpec spec) {

    //Get top level frame
    JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(MasterPanel);

    //Create dialog for choosing gearspec file
    FileDialog fd = new FileDialog(topFrame, "Save .gearspec file", FileDialog.SAVE);
    fd.setDirectory(System.getProperty("user.home"));
    // Gets the name that is specified for the spec in the beginning
    fd.setFile(spec.getName() + ".gearspec");
    fd.setVisible(true);/*from w  w  w . j  a v a2  s  . co  m*/
    //Get file
    String filename = fd.getFile();
    if (filename == null) {
        System.out.println("You cancelled the choice");
        return false;
    } else {
        System.out.println("You chose " + filename);

        //Get spec file
        File specFile = new File(fd.getDirectory() + Utils.pathSeparator() + filename);

        //Serialize spec to string
        String gearString = gson.toJson(spec);

        try {
            //If it exists, set it as the selected file path
            if (specFile.exists()) {
                FileUtils.forceDelete(specFile);
            }

            //Write new spec
            FileUtils.write(specFile, gearString);
        } catch (IOException e) {
            e.printStackTrace();
            showSaveErrorDialog();
            return false;
        }

        return true;
    }
}

From source file:edu.wustl.lookingglass.community.CommunityRepository.java

private Git load() throws IOException, URISyntaxException, IllegalStateException, GitAPIException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository = builder.setGitDir(this.gitDir).readEnvironment().build();

    Git newGit;/*from  www .  j  av  a 2  s. c  om*/
    if (hasAtLeastOneReference(repository)) {
        // The repository is valid
        newGit = new Git(repository);
    } else {
        // The current git dir isn't valid... so let's make a new one.
        Logger.warning("invalid git dir found " + this.gitDir + "; deleting.");
        FileUtils.forceDelete(this.gitDir);
        newGit = init();
    }

    // We need to make sure this repo stays in shape...
    // so let's do some maintenance every now and then...
    Properties gcStats = newGit.gc().getStatistics();
    int looseObjects = Integer.valueOf(gcStats.getProperty("numberOfLooseObjects", "0"));
    if ((AUTO_GC_LOOSE_OBJECTS != 0) && (looseObjects > AUTO_GC_LOOSE_OBJECTS)) {
        newGit.gc().call();
    }

    return newGit;
}

From source file:ddf.security.pdp.xacml.processor.BalanaPdpTest.java

@Test
public void testBalanaPdp_policies_directory_does_not_exist() throws PdpException, IOException {
    LOGGER.debug("\n\n\n##### testBalanaPdp_policies_directory_does_not_exist");

    // Perform Test on new directory
    // Expect directory to be created
    new BalanaPdp(TEST_CREATION_DIR);

    // Delete the directory that was just created
    FileUtils.forceDelete(new File(TEST_CREATION_DIR));
}

From source file:com.kegare.caveworld.plugin.mceconomy.GuiShopEntry.java

@Override
protected void actionPerformed(GuiButton button) {
    if (button.enabled) {
        switch (button.id) {
        case 0:/* w  w  w  .  j av  a2 s. c om*/
            if (editMode) {
                if (Strings.isNullOrEmpty(itemField.getText())
                        || !GameData.getItemRegistry().containsKey(itemField.getText())
                        || NumberUtils.toInt(stackField.getText()) <= 0) {
                    return;
                }

                productList.selected.setProductItem(new ItemStack(
                        GameData.getItemRegistry().getObject(itemField.getText()),
                        NumberUtils.toInt(stackField.getText()), NumberUtils.toInt(damageField.getText())));
                productList.selected.setCost(NumberUtils.toInt(costField.getText()));

                hoverCache.remove(productList.selected);

                actionPerformed(cancelButton);

                productList.scrollToSelected();
            } else {
                boolean flag = ShopProductManager.instance().getShopProducts().size() != productList.products
                        .size();

                ShopProductManager.instance().getShopProducts().clear();

                if (flag) {
                    try {
                        FileUtils.forceDelete(new File(MCEconomyPlugin.shopCfg.toString()));

                        MCEconomyPlugin.shopCfg.load();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                for (ShopProduct product : productList.products) {
                    ShopProductManager.instance().addShopProduct(product);
                }

                if (MCEconomyPlugin.shopCfg.hasChanged()) {
                    MCEconomyPlugin.shopCfg.save();
                }

                actionPerformed(cancelButton);
            }

            break;
        case 1:
            if (editMode) {
                actionPerformed(cancelButton);
            } else {
                editMode = true;
                initGui();

                productList.scrollToSelected();

                itemField.setText(GameData.getItemRegistry()
                        .getNameForObject(productList.selected.getProductItem().getItem()));
                damageField.setText(Integer.toString(productList.selected.getProductItem().getItemDamage()));
                stackField.setText(Integer.toString(productList.selected.getProductItem().stackSize));
                costField.setText(Integer.toString(productList.selected.getcost()));
            }

            break;
        case 2:
            if (editMode) {
                editMode = false;
                initGui();
            } else {
                mc.displayGuiScreen(parentScreen);
            }

            break;
        case 3:
            mc.displayGuiScreen(new GuiSelectItem(this));
            break;
        case 4:
            if (productList.products.remove(productList.selected)) {
                int i = productList.contents.indexOf(productList.selected);

                productList.contents.remove(i);
                productList.selected = productList.contents.get(i, productList.contents.get(--i, null));
            }

            break;
        case 5:
            for (Object obj : productList.products.toArray()) {
                productList.selected = (ShopProduct) obj;

                actionPerformed(removeButton);
            }

            break;
        case 6:
            CaveConfigGui.detailInfo = detailInfo.isChecked();
            break;
        case 7:
            CaveConfigGui.instantFilter = instantFilter.isChecked();
            break;
        }
    }
}

From source file:eu.edisonproject.training.execute.Main.java

private static void calculateTFIDF(String in, String out) throws IOException {
    File tmpFolder = null;/* www  . ja  v  a  2 s.co m*/
    try {
        String contextName = FilenameUtils.removeExtension(in.substring(in.lastIndexOf(File.separator) + 1));
        ITFIDFDriver tfidfDriver = new TFIDFDriverImpl(contextName);
        File inFile = new File(in);

        String workingFolder = System.getProperty("working.folder");
        if (workingFolder == null) {
            workingFolder = prop.getProperty("working.folder", System.getProperty("java.io.tmpdir"));
        }

        tmpFolder = new File(workingFolder + File.separator + System.currentTimeMillis());

        tmpFolder.mkdir();
        tmpFolder.deleteOnExit();

        setTFIDFDriverImplPaths(inFile, tmpFolder);

        tfidfDriver.executeTFIDF(tmpFolder.getAbsolutePath());
        tfidfDriver.driveProcessResizeVector();
        File ctxPath = new File(TFIDFDriverImpl.CONTEXT_PATH);
        for (File f : ctxPath.listFiles()) {
            if (FilenameUtils.getExtension(f.getName()).endsWith("csv")) {
                FileUtils.moveFile(f, new File(out + File.separator + f.getName()));
            }
        }
    } finally {
        if (tmpFolder != null && tmpFolder.exists()) {
            tmpFolder.delete();
            FileUtils.forceDelete(tmpFolder);
        }
    }
}

From source file:architecture.ee.web.attachment.DefaultImageManager.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void saveOrUpdate(Image image) {
    try {/*from   ww w . j a  va  2  s.c o m*/
        if (image.getImageId() <= 0) {
            imageDao.createImage(image);
            imageDao.saveImageInputStream(image, image.getInputStream());
        } else {
            Date now = new Date();
            ((ImageImpl) image).setModifiedDate(now);
            imageDao.updateImage(image);
            imageDao.saveImageInputStream(image, image.getInputStream());
        }

        Collection<File> files = FileUtils.listFiles(getImageCacheDir(),
                FileFilterUtils.prefixFileFilter(image.getImageId() + ""), null);
        for (File file : files) {
            FileUtils.forceDelete(file);
        }
        Image imageToUse = getImage(image.getImageId());
        imageCache.remove(imageToUse.getImageId());
    } catch (Exception e) {
        throw new SystemException(e);
    }
}

From source file:fr.gael.dhus.datastore.processing.impl.ProcessProductPrepareDownload.java

@Override
public void removeProcessing(Product product) {
    String zip_file_string = product.getDownloadablePath();
    if (zip_file_string == null)
        return;/*from   w w w . j  a v a  2s .co  m*/
    File zip_file = new File(zip_file_string);

    if ((zip_file_string != null) && ((zip_file.exists())) && incomingManager.isInIncoming(zip_file)) {
        if (IncomingManager.INCOMING_PRODUCT_DIR.equals(zip_file.getParentFile().getName()))
            zip_file = zip_file.getParentFile();
        if (HierarchicalDirectoryBuilder.DHUS_ENTRY_NAME.equals(zip_file.getParentFile().getName()))
            zip_file = zip_file.getParentFile();
        try {
            FileUtils.forceDelete(zip_file);
        } catch (IOException e) {
            logger.error("Unable to remove downloadable path " + zip_file_string);
        }
    }
}

From source file:gobblin.runtime.job_catalog.FSJobCatalogHelperTest.java

@AfterClass
public void tearDown() throws IOException {
    if (this.jobConfigDir != null) {
        FileUtils.forceDelete(this.jobConfigDir);
    }/*  w  w  w. j ava  2 s.  c  o m*/
}

From source file:hoot.services.controllers.ingest.FileUploadResourceTest.java

@Test
@Category(UnitTest.class)
public void TestCreateNativeRequestOgrZipAndShp() throws Exception {
    String input = "fgdb_ogr.zip";
    String jobId = "test-id-123";
    String wkdirpath = homeFolder + "/upload/" + jobId;
    File workingDir = new File(wkdirpath);
    FileUtils.forceMkdir(workingDir);/*from ww  w  . j  a va 2 s .  c om*/
    org.junit.Assert.assertTrue(workingDir.exists());

    File srcFile = new File(homeFolder + "/test-files/service/FileUploadResourceTest/" + input);
    File destFile = new File(wkdirpath + "/" + input);
    FileUtils.copyFile(srcFile, destFile);
    org.junit.Assert.assertTrue(destFile.exists());

    FileUploadResource res = new FileUploadResource();

    // Let's test zip
    JSONArray results = new JSONArray();
    JSONObject zipStat = new JSONObject();
    List<String> inputsList = new ArrayList<String>();
    inputsList.add(input);

    res._buildNativeRequest(jobId, "fgdb_ogr", "zip", input, results, zipStat);

    int shpCnt = 0;
    int osmCnt = 0;
    int fgdbCnt = 0;

    int zipCnt = 0;
    int shpZipCnt = 0;
    int osmZipCnt = 0;
    int fgdbZipCnt = 0;
    List<String> zipList = new ArrayList<String>();

    shpZipCnt += (Integer) zipStat.get("shpzipcnt");
    fgdbZipCnt += (Integer) zipStat.get("fgdbzipcnt");
    osmZipCnt += (Integer) zipStat.get("osmzipcnt");

    zipList.add("fgdb_ogr");
    zipCnt++;

    // shape
    input = "TransportationGroundCrv.shp";
    srcFile = new File(homeFolder + "/test-files/service/FileUploadResourceTest/" + input);
    destFile = new File(wkdirpath + "/" + input);
    FileUtils.copyFile(srcFile, destFile);
    org.junit.Assert.assertTrue(destFile.exists());

    inputsList.add(input);

    res._buildNativeRequest(jobId, "TransportationGroundCrv", "shp", input, results, zipStat);

    shpCnt += (Integer) zipStat.get("shpcnt");
    fgdbCnt += (Integer) zipStat.get("fgdbcnt");
    osmCnt += (Integer) zipStat.get("osmcnt");

    // Test zip containing fgdb + shp
    JSONArray resA = res._createNativeRequest(results, zipCnt, shpZipCnt, fgdbZipCnt, osmZipCnt, shpCnt,
            fgdbCnt, osmCnt, zipList, "TDSv61.js", jobId, "fgdb_ogr", inputsList);

    JSONObject req = (JSONObject) resA.get(0);
    JSONArray params = (JSONArray) req.get("params");

    int nP = 0;

    for (Object o : params) {
        JSONObject oJ = (JSONObject) o;

        if (oJ.get("INPUT") != null) {
            org.junit.Assert.assertTrue(oJ.get("INPUT").toString().equals(
                    "\"fgdb_ogr/DcGisRoads.gdb\" \"fgdb_ogr/jakarta_raya_coastline.shp\" \"TransportationGroundCrv.shp\" "));
            nP++;
        }

        if (oJ.get("INPUT_PATH") != null) {
            org.junit.Assert.assertTrue(oJ.get("INPUT_PATH").toString().equals("upload/test-id-123"));
            nP++;
        }

        if (oJ.get("INPUT_TYPE") != null) {
            org.junit.Assert.assertTrue(oJ.get("INPUT_TYPE").toString().equals("OGR"));
            nP++;
        }

        if (oJ.get("UNZIP_LIST") != null) {
            org.junit.Assert.assertTrue(oJ.get("UNZIP_LIST").toString().equals("fgdb_ogr"));
            nP++;
        }
    }
    org.junit.Assert.assertTrue(nP == 4);
    FileUtils.forceDelete(workingDir);
}