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

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

Introduction

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

Prototype

public static void forceMkdir(File directory) throws IOException 

Source Link

Document

Makes a directory, including any necessary but nonexistent parent directories.

Usage

From source file:com.norconex.collector.core.data.store.impl.jdbc.JDBCCrawlDataStore.java

public JDBCCrawlDataStore(Database database, String path, boolean resume, IJDBCSerializer serializer) {
    super();/*w w w  .j a v a  2 s .  co  m*/

    this.database = database;
    this.serializer = serializer;
    String fullPath = new File(path).getAbsolutePath();

    LOG.info("Initializing crawl document reference store: " + fullPath);

    try {
        FileUtils.forceMkdir(new File(fullPath));
    } catch (IOException e) {
        throw new CrawlDataStoreException("Cannot create crawl store directory: " + fullPath, e);
    }
    if (database == Database.DERBY) {
        System.setProperty("derby.system.home", fullPath + "/derby/log");
        this.dbDir = fullPath + "/derby/db";
    } else {
        this.dbDir = fullPath + "/h2/db";
    }
    this.datasource = createDataSource(dbDir);
    boolean incrementalRun;
    try {
        incrementalRun = ensureTablesExist();
    } catch (SQLException e) {
        throw new CrawlDataStoreException("Problem creating crawl store.", e);
    }
    if (resume) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Active count: " + getActiveCount());
            LOG.debug("Processed count: " + getProcessedCount());
            LOG.debug("Putting active references back in the queue...");
        }
        copyCrawlDatasToQueue(TABLE_ACTIVE);
        LOG.debug("Cleaning active database...");
        sqlClearTable(TABLE_ACTIVE);
    } else if (incrementalRun) {
        LOG.info("Caching processed reference from last run (if any)...");
        LOG.debug("Rename processed table to cache...");
        sqlUpdate("DROP TABLE " + TABLE_CACHE);
        if (database == Database.DERBY) {
            sqlUpdate("RENAME TABLE " + TABLE_PROCESSED_VALID + " TO " + TABLE_CACHE);
        } else {
            sqlUpdate("ALTER TABLE " + TABLE_PROCESSED_VALID + " RENAME TO " + TABLE_CACHE);
        }
        LOG.debug("Cleaning queue table...");
        sqlClearTable(TABLE_QUEUE);
        LOG.debug("Cleaning invalid references table...");
        sqlClearTable(TABLE_PROCESSED_INVALID);
        LOG.debug("Cleaning active table...");
        sqlClearTable(TABLE_ACTIVE);
        LOG.debug("Re-creating processed table...");
        sqlCreateTable(TABLE_PROCESSED_VALID);
    }
    LOG.info("Done crawl document reference store.");
}

From source file:hudson.plugins.sonar.SonarRunnerBuilderTest.java

@Before
public void prepareMockWorkspace() throws IOException {
    workspace = temp.newFolder();//from   ww  w  . j a va2  s  .com
    moduleDir = new File(workspace, "trunk");
    FileUtils.forceMkdir(moduleDir);
    args = new ArgumentListBuilder();
    argsBuilder = new ExtendedArgumentListBuilder(args, false);
    AbstractProject<?, ?> p = mock(AbstractProject.class);
    SCM scm = mock(SCM.class);
    FilePath workspacePath = new FilePath(workspace);
    when(scm.getModuleRoot(eq(workspacePath), any(AbstractBuild.class))).thenReturn(new FilePath(moduleDir));
    when(p.getScm()).thenReturn(scm);
    build = new MyBuild(p);
    build.setWorkspace(workspacePath);
    listener = mock(BuildListener.class);
    env = new EnvVars();
}

From source file:com.shopzilla.hadoop.repl.commands.util.ClusterStateManager.java

public void serializePath(final Path path, final File output) throws Exception {
    final File tmpRoot = Files.createTempDir();
    final File tmp = new File(tmpRoot, "hdfs");
    FileUtils.forceMkdir(tmp);
    new FsShell(fs.getConf()).run(new String[] { "-copyToLocal", path.toString(), tmp.getAbsolutePath() });
    compressFile(tmp, output);//from w  w w  . java 2 s.c  o  m
    FileUtils.deleteQuietly(tmpRoot);
}

From source file:eu.openanalytics.rsb.data.FileResultStore.java

public void store(final PersistedResult result) throws IOException {
    final String resultFileName = result.getJobId().toString()
            + (result.isSuccess() ? "" : ERROR_FILE_INFIX_EXTENSION) + "."
            + Util.getResourceType(result.getMimeType());

    final File resultsDirectory = getResultsDirectory(result.getApplicationName(), result.getUserName());
    FileUtils.forceMkdir(resultsDirectory);
    final File resultFile = new File(resultsDirectory, resultFileName);

    final InputStream resultData = result.getData();
    final FileOutputStream fos = new FileOutputStream(resultFile);
    IOUtils.copy(resultData, fos);/* w  w w . j  av a  2s.com*/
    IOUtils.closeQuietly(result.getData());
    IOUtils.closeQuietly(fos);
}

From source file:edu.monash.merc.util.file.DMFileUtils.java

public static void createDirectory(String dirName) {
    if (dirName == null) {
        throw new DMFileException("directory name must not be null");
    }//from   www .  j a  v  a2 s.c om
    try {
        FileUtils.forceMkdir(new File(dirName));
    } catch (Exception e) {
        throw new DMFileException(e);
    }
}

From source file:it.geosolutions.geobatch.unredd.script.util.FileManager.java

public static String mkUNREDDdir(String basepath, String layer, String year, String month) throws IOException {
    String path = basepath + System.getProperty("file.separator") + layer + System.getProperty("file.separator")
            + year;//from   ww w  .j a v  a2  s. co  m
    if (month != null)
        path += (System.getProperty("file.separator") + month);
    File directory = new File(path);
    FileUtils.forceMkdir(directory);
    return path;
}

From source file:com.blockwithme.longdb.leveldb.LevelDBDatabase.java

@Override
protected LevelDBTable createInternal(final Base36 theTable, final BETableProfile theProfile) {
    try {/* w  ww  . jav a  2s  .c o m*/
        final File databaseDir = getDir(theTable.toFixedString());
        FileUtils.forceMkdir(databaseDir);
        final LevelDBTable tableInstance = new LevelDBTable(this, databaseDir, theTable, false);
        return tableInstance;
    } catch (final Exception e) {
        LOG.error("Exception Occurred in - createInternal(Base36 table=" + theTable
                + ", BETableProfile profile=" + theProfile + ")", e);
        throw new DBException("Error creating table.", e);
    }
}

From source file:com.temenos.interaction.loader.detector.DirectoryChangeActionNotifier.java

@Override
public void setResources(Collection<? extends File> resources) {
    ArrayList<File> existingResources = new ArrayList<File>();
    // temporary fix to avoid crashes when trying to watch inexisting directories
    // just create them if they don't exist
    for (File file : resources) {
        if (!file.exists()) {
            try {
                FileUtils.forceMkdir(file);
                existingResources.add(file);
            } catch (IOException ex) {
                logger.warn("Could not create configured directory to monitor.", ex);
            }// w w  w  .  ja  va2  s.  com
        } else {
            existingResources.add(file);
        }
    }

    this.resources = existingResources;
    initWatchers(this.resources);
}

From source file:com.palantir.paxos.PaxosStateLogImpl.java

public PaxosStateLogImpl(String path) {
    this.path = path;
    try {//w  w w  . java  2s.c o m
        FileUtils.forceMkdir(new File(path));
        if (getGreatestLogEntry() == PaxosAcceptor.NO_LOG_ENTRY) {
            // For a brand new log, we create a lowest entry so #getLeastLogEntry will return the right thing
            // If we didn't add this then we could miss seq 0 and accept seq 1, then when we restart we will
            // start ignoring seq 0 which may cause things to get stalled
            FileUtils.touch(new File(path, getFilenameFromSeq(PaxosAcceptor.NO_LOG_ENTRY)));
        }
    } catch (IOException e) {
        throw new RuntimeException("IO problem related to the path " + new File(path).getAbsolutePath(), e);
    }
}

From source file:com.btoddb.fastpersitentqueue.MemorySegmentSerializerTest.java

@Before
public void setup() throws IOException {
    theDir = new File("tmp/junitTmp_" + new UUID().toString());
    FileUtils.forceMkdir(theDir);

    serializer = new MemorySegmentSerializer();
    serializer.setDirectory(theDir.getCanonicalFile());
}