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

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

Introduction

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

Prototype

public static void cleanDirectory(File directory) throws IOException 

Source Link

Document

Cleans a directory without deleting it.

Usage

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

public static void clearDirectory(File dir) {
    try {//from  w  ww.j  a va 2  s  .c o  m
        if (dir == null || !dir.exists()) {
            return;
        }
        FileUtils.cleanDirectory(dir);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java

@BeforeAll()
static void setupAll() {

    String ffmpegOutput = commandLine.executeCommand("which ffmpeg");
    if (ffmpegOutput == null || ffmpegOutput.isEmpty()) {
        log.error("ffmpeg package is not installed in the host machine");
        Assert.fail();/*from  w ww . ja  v a  2 s  .  c  o  m*/
        return;
    } else {
        log.info("ffmpeg is installed and accesible");
    }

    WebDriverManager.chromedriver().setup();
    WebDriverManager.firefoxdriver().setup();

    String appUrl = System.getProperty("APP_URL");
    if (appUrl != null) {
        APP_URL = appUrl;
    }
    log.info("Using URL {} to connect to openvidu-testapp", APP_URL);

    String openviduUrl = System.getProperty("OPENVIDU_URL");
    if (openviduUrl != null) {
        OPENVIDU_URL = openviduUrl;
    }
    log.info("Using URL {} to connect to openvidu-server", OPENVIDU_URL);

    String openvidusecret = System.getProperty("OPENVIDU_SECRET");
    if (openvidusecret != null) {
        OPENVIDU_SECRET = openvidusecret;
    }
    log.info("Using secret {} to connect to openvidu-server", OPENVIDU_SECRET);

    try {
        log.info("Cleaning folder /opt/openvidu/recordings");
        FileUtils.cleanDirectory(new File("/opt/openvidu/recordings"));
    } catch (IOException e) {
        log.error(e.getMessage());
    }
    OV = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
}

From source file:eu.dime.ps.storage.datastore.impl.DataStoreImpl.java

@Override
protected void finalize() throws Throwable {
    db.close();//from  w w w  .  j  a v a  2 s  . c  om
    FileUtils.cleanDirectory(new File(blobPath + File.separator + "tmp-write"));
    instances--;
    super.finalize();
}

From source file:com.enioka.jqm.test.helpers.TestHelpers.java

public static void cleanup(EntityManager em) {
    em.getTransaction().begin();/*from w w  w .  j  av a  2s.  c o  m*/
    em.createQuery("DELETE GlobalParameter WHERE 1=1").executeUpdate();
    em.createQuery("DELETE Deliverable WHERE 1=1").executeUpdate();
    em.createQuery("DELETE DeploymentParameter WHERE 1=1").executeUpdate();
    em.createQuery("DELETE Message WHERE 1=1").executeUpdate();
    em.createQuery("DELETE History WHERE 1=1").executeUpdate();
    em.createQuery("DELETE JobDefParameter WHERE 1=1").executeUpdate();
    em.createQuery("DELETE RuntimeParameter WHERE 1=1").executeUpdate();
    em.createQuery("DELETE JobInstance WHERE 1=1").executeUpdate();
    em.createQuery("DELETE Node WHERE 1=1").executeUpdate();
    em.createQuery("DELETE JobDef WHERE 1=1").executeUpdate();
    em.createQuery("DELETE Queue WHERE 1=1").executeUpdate();
    em.createQuery("DELETE JndiObjectResourceParameter WHERE 1=1").executeUpdate();
    em.createQuery("DELETE JndiObjectResource WHERE 1=1").executeUpdate();
    em.createQuery("DELETE PKI WHERE 1=1").executeUpdate();
    em.createQuery("DELETE RPermission WHERE 1=1").executeUpdate();
    em.createQuery("DELETE RRole WHERE 1=1").executeUpdate();
    em.createQuery("DELETE RUser WHERE 1=1").executeUpdate();

    em.getTransaction().commit();

    try {
        // Conf dir may contain certificates and certificate stores
        if ((new File("./conf")).isDirectory()) {
            FileUtils.deleteDirectory(new File("./conf"));
        }
        // All logs
        if ((new File("./logs")).isDirectory()) {
            FileUtils.deleteDirectory(new File("./logs"));
        }
        // The war...
        if ((new File("./webapp")).isDirectory()) {
            FileUtils.deleteDirectory(new File("./webapp"));
        }
        // Where files created by payloads are stored
        File f = TestHelpers.node == null ? null : new File(TestHelpers.node.getDlRepo());
        if (f != null && f.isDirectory()) {
            FileUtils.cleanDirectory(new File(TestHelpers.node.getDlRepo()));
        }
        // Temp dir where files downloaded by the API are stored (supposed to be self-destructible file but anyway)
        if ((new File(System.getProperty("java.io.tmpdir") + "/jqm")).isDirectory()) {
            FileUtils.cleanDirectory(new File(System.getProperty("java.io.tmpdir") + "/jqm"));
        }
    } catch (IOException e) {
        // Nothing to do
    }
}

From source file:com.juancarlosroot.threads.SimulatedUser.java

private void deleteFilesInsideFolder(String folderName) {
    Path currentRelativePath = Paths.get("");
    String s = currentRelativePath.toAbsolutePath().toString();
    File theFolder = new File(s + "/" + folderName);

    try {/*from  www .  j  a  va 2s .c  o m*/
        FileUtils.cleanDirectory(theFolder);
        System.out.println("Se han borrado los archivos de : " + folderName);
    } catch (IOException ex) {
        Logger.getLogger(SimulatedUser.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("Error al borrar los archivos de : " + folderName);
    }
}

From source file:info.donsun.cache.filecache.FileCache.java

@Override
public void clear() throws CacheException {
    synchronized (LOCK) {
        File file = new File(config.getDir());
        if (file.exists()) {
            try {
                FileUtils.cleanDirectory(file);
            } catch (IOException e) {
                throw new CacheException("Clean directory " + config.getDir() + " fail.", e);
            }//from   w  w w  . j  av  a  2s  .  co m
        }

    }
}

From source file:com.github.ipaas.ideploy.agent.util.SVNUtil.java

/**
 * svnremovePathlocalPath  ??//ww  w  . j  av  a 2  s. co  m
 * @param svnClientManager svn?
 * @param remotePath  svn
 * @param revision   
 * @param localPath    ?
         
 */
public static void export(SVNClientManager svnClientManager, String remotePath, long revision, String localPath)
        throws Exception {
    File localF = new File(localPath);
    if (!localF.exists()) {
        localF.mkdirs();
    } else {
        FileUtils.cleanDirectory(localF);
    }

    SVNUpdateClient svnUpdateClient = svnClientManager.getUpdateClient();
    svnUpdateClient.doExport(SVNURL.parseURIEncoded(Constants.CRS_REPOS + remotePath), new File(localPath),
            SVNRevision.HEAD, SVNRevision.create(revision), null, true, SVNDepth.INFINITY);
}

From source file:com.alibaba.jstorm.hdfs.transaction.RocksDbHdfsState.java

private void initLocalRocksDbDir() {
    try {//from w  w  w.j  av  a 2  s.c  om
        File file = new File(rocksDbDir);
        if (file.exists())
            FileUtils.cleanDirectory(file);
        FileUtils.forceMkdir(new File(rocksDbCheckpointDir));
    } catch (IOException e) {
        LOG.error("Failed to create dir for path=" + rocksDbCheckpointDir, e);
        throw new RuntimeException(e.getMessage());
    }
}

From source file:com.vsquaresystem.safedeals.marketprice.MarketPriceService.java

public boolean saveExcelToDatabase() throws IOException {

    Vector dataHolder = read();/* w  w w .  ja  va  2s  . co m*/
    marketPriceDAL.truncateAll();
    dataHolder.remove(0);
    System.out.println("data line 147" + dataHolder);
    MarketPrice marketPrice = new MarketPrice();
    String id = "";
    String cityId = "";
    String locationId = "";
    String year = "";
    String month = "";
    String mpAgriLandLowest = "";
    String mpAgriLandHighest = "";
    String mpPlotLowest = "";
    String mpPlotHighest = "";
    String mpResidentialLowest = "";
    String mpResidentialHighest = "";
    String mpCommercialLowest = "";
    String mpCommercialHighest = "";
    String sdZoneId = "";
    String locationTypeId = "";
    String locationCategories = "";
    String description = "";
    String majorApproachRoad = "";
    String sourceOfWater = "";
    String publicTransport = "";
    String advantage = "";
    String disadvantage = "";
    String population = "";
    String migrationRate = "";
    String isCommercialCenter = "";

    DataFormatter formatter = new DataFormatter();
    for (Iterator iterator = dataHolder.iterator(); iterator.hasNext();) {

        List list = (List) iterator.next();

        System.out.println("list for save" + list);
        cityId = list.get(1).toString();
        locationId = list.get(2).toString();
        year = list.get(3).toString();
        month = list.get(4).toString();
        mpAgriLandLowest = list.get(5).toString();
        mpAgriLandHighest = list.get(6).toString();
        mpPlotLowest = list.get(7).toString();
        mpPlotHighest = list.get(8).toString();
        mpResidentialLowest = list.get(9).toString();
        mpResidentialHighest = list.get(10).toString();
        mpCommercialLowest = list.get(11).toString();
        mpCommercialHighest = list.get(12).toString();

        List<Integer> numberList = new ArrayList<Integer>();

        try {

            marketPrice.setCityId(Integer.parseInt(cityId));
            marketPrice.setLocationId(Integer.parseInt(locationId));
            marketPrice.setYear(Integer.parseInt(year));
            marketPrice.setMonth(Integer.parseInt(month));
            marketPrice.setMpAgriLandLowest(Double.parseDouble(mpAgriLandLowest));
            marketPrice.setMpAgriLandHighest(Double.parseDouble(mpAgriLandHighest));

            marketPrice.setMpPlotLowest(Double.parseDouble(mpPlotLowest));
            marketPrice.setMpPlotHighest(Double.parseDouble(mpPlotHighest));

            marketPrice.setMpResidentialLowest(Double.parseDouble(mpResidentialLowest));
            marketPrice.setMpResidentialHighest(Double.parseDouble(mpResidentialHighest));

            marketPrice.setMpCommercialLowest(Double.parseDouble(mpCommercialLowest));
            marketPrice.setMpCommercialHighest(Double.parseDouble(mpCommercialHighest));

            marketPriceDAL.insert(marketPrice);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    File excelFile = attachmentUtils.getDirectoryByAttachmentType(AttachmentUtils.AttachmentType.MARKET_PRICE);
    FileUtils.cleanDirectory(excelFile);
    return true;

}

From source file:dbseer.old.middleware.MiddlewareSocket.java

public synchronized boolean startMonitoring() throws IOException {
    if (output == null) {
        errorMessage = "Middleware not connected.";
        return false;
    }//  www .  j  ava  2s. co  m
    synchronized (this.lock) {
        output.writeInt(PACKET_START_MONITORING);
        output.writeLong(0);
        output.flush();

        int packetId = input.readInt();
        long packetLength = input.readLong();
        byte[] packetData = new byte[(int) packetLength];

        int readBytes = 0;

        while (readBytes < packetLength) {
            readBytes += input.read(packetData, readBytes, (int) packetLength - readBytes);
        }

        if (packetId == PACKET_START_MONITORING_SUCCESS) {
            // clear live dataset directory
            File liveDir = new File(DBSeerGUI.userSettings.getDBSeerRootPath() + File.separator
                    + DBSeerConstants.LIVE_DATASET_PATH);
            if (liveDir.exists() && liveDir.isDirectory()) {
                FileUtils.cleanDirectory(liveDir);
            }

            startMonitoringProcesses(true);

            return true;
        } else if (packetId == PACKET_START_MONITORING_FAILURE) {
            errorMessage = "Failed to start monitoring.";
        } else if (packetId == PACKET_LOGIN_FAILURE) {
            errorMessage = String.valueOf(packetData);
        } else {
            errorMessage = "Start monitoring failed: invalid packet. (ID = " + packetId + ")";
        }
        return false;
    }
}