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:jp.co.tis.gsp.tools.dba.mojo.GenerateDdlMojo.java

/**
 * Generate DDL.//from   w  w  w  .  ja  va2s. c o  m
 *
 * @throws MojoExecutionException 
 * @throws MojoFailureException 
 */
@Override
protected void executeMojoSpec() throws MojoExecutionException, MojoFailureException {
    if (outputDirectory.exists()) {
        try {
            FileUtils.cleanDirectory(outputDirectory);
        } catch (IOException e) {
            throw new MojoExecutionException("Can't clean outputDirectory:" + outputDirectory);
        }
    } else {
        try {
            FileUtils.forceMkdir(outputDirectory);
        } catch (IOException e) {
            throw new MojoExecutionException("Can't create outputDirectory:" + outputDirectory);
        }
    }

    ObjectBrowserErParser parser = new ObjectBrowserErParser();
    parser.setOutputDirectory(outputDirectory);
    parser.setSchema(schema);
    parser.setUrl(url);
    parser.setUser(user);
    parser.setDdlTemplateFileDir(ddlTemplateFileDir);
    Dialect dialect = DialectFactory.getDialect(url, driver);
    parser.setTypeMapper(dialect.getTypeMapper());

    parser.setPrintTable(dialect.canPrintTable());
    parser.setPrintIndex(dialect.canPrintIndex());
    parser.setPrintForeignKey(dialect.canPrintForeignKey());
    parser.setPrintView(dialect.canPrintView());
    parser.setLengthSemantics(lengthSemantics);
    parser.setAllocationSize(allocationSize);
    ;
    try {
        parser.parse(erdFile);
    } catch (Exception e) {
        throw new MojoExecutionException("DDL generate", e);
    }
}

From source file:hoot.services.ingest.MultipartSerializerTest.java

@Test
@Category(UnitTest.class)
public void TestserializeFGDB() throws Exception {
    String jobId = "123-456-789";
    String wkdirpath = homeFolder + "/upload/" + jobId;
    File workingDir = new File(wkdirpath);
    FileUtils.forceMkdir(workingDir);
    org.junit.Assert.assertTrue(workingDir.exists());

    List<FileItem> fileItemsList = new ArrayList<FileItem>();

    FileItemFactory factory = new DiskFileItemFactory(16, null);
    String textFieldName = "textField";

    FileItem item = factory.createItem(textFieldName, "application/octet-stream", true,
            "fgdbTest.gdb/dummy1.gdbtable");

    String textFieldValue = "0123456789";
    byte[] testFieldValueBytes = textFieldValue.getBytes();

    OutputStream os = item.getOutputStream();
    os.write(testFieldValueBytes);//from  w w  w .j a  v a  2s  .c om
    os.close();

    File out = new File(wkdirpath + "/buffer.tmp");
    item.write(out);
    fileItemsList.add(item);
    org.junit.Assert.assertTrue(out.exists());

    Map<String, String> uploadedFiles = new HashMap<String, String>();
    Map<String, String> uploadedFilesPaths = new HashMap<String, String>();

    _ms._serializeFGDB(fileItemsList, jobId, uploadedFiles, uploadedFilesPaths);

    org.junit.Assert.assertEquals("GDB", uploadedFiles.get("fgdbTest"));
    org.junit.Assert.assertEquals("fgdbTest.gdb", uploadedFilesPaths.get("fgdbTest"));

    File fgdbpath = new File(wkdirpath + "/fgdbTest.gdb");
    org.junit.Assert.assertTrue(fgdbpath.exists());

    File content = new File(wkdirpath + "/fgdbTest.gdb/dummy1.gdbtable");
    org.junit.Assert.assertTrue(content.exists());

    FileUtils.forceDelete(workingDir);
}

From source file:net.hillsdon.reviki.configuration.DataDirImpl.java

/**
 * @return A configuration location if we can, otherwise null.
 */// w  w w  .  ja  va  2  s . c  om
private File getConfigurationLocation() {
    String location = trimToNull(_servletContext.getInitParameter(DATA_DIR_CONTEXT_PARAM));
    if (location == null) {
        try {
            location = Path.join(_defaultBaseDir, DEFAULT_CONFIG_DIR_NAME);
        } catch (SecurityException ex) {
        }
    }
    if (location == null) {
        return null;
    }
    File dir = new File(location);
    try {
        if (!dir.exists()) {
            try {
                FileUtils.forceMkdir(dir);
            } catch (IOException ex) {
                LOG.error("Failed to create data area.", ex);
                return null;
            }
        }
    } catch (SecurityException ex) {
        return null;
    }
    return dir;
}

From source file:net.erdfelt.android.sdkfido.project.Dir.java

public void ensureExists() throws FetchException {
    if (basedir.exists()) {
        return;/*from   w ww .j ava  2  s  .co m*/
    }
    try {
        FileUtils.forceMkdir(basedir);
    } catch (IOException e) {
        throw new FetchException("Unable to ensure directory exists: " + basedir, e);
    }
}

From source file:ml.shifu.shifu.core.processor.CreateModelProcessor.java

/**
 * Runner, running the create model processor
 * /*from   w  w  w . j  a v a  2s  . co m*/
 * @throws IOException
 *             - when creating files
 */
@Override
public int run() throws IOException {
    File modelSetFolder = new File(name);
    if (modelSetFolder.exists()) {
        log.error("ModelSet - {} already exists.", name);
        return 1;
    }

    try {
        log.info("Creating ModelSet Folder: " + modelSetFolder.getCanonicalPath() + "...");
        FileUtils.forceMkdir(modelSetFolder);

        log.info("Creating Initial ModelConfig.json ...");

        // how to check hdfs
        boolean enableHadoop = HDFSUtils.isDistributedMode();
        if (enableHadoop) {
            log.info("Enable DIST/MAPRED mode because Hadoop cluster is detected.");
        } else {
            log.info("Enable LOCAL mode because Hadoop cluster is not detected.");
        }

        modelConfig = ModelConfig.createInitModelConfig(name, alg, description, enableHadoop);

        JSONUtils.writeValue(new File(modelSetFolder.getCanonicalPath() + File.separator + "ModelConfig.json"),
                modelConfig);

        createHead(modelSetFolder.getCanonicalPath());

        log.info("Step Finished: new");
    } catch (ShifuException e) {
        log.error("Error:" + e.getError().toString() + "; msg:" + e.getMessage(), e);
        return -1;
    } catch (Exception e) {
        log.error("Error:" + e.getMessage(), e);
        return -1;
    }
    return 0;
}

From source file:com.linkedin.pinot.segments.v1.creator.BitmapInvertedIndexCreatorTest.java

@Test
public void testSingleValue() throws IOException {

    boolean singleValue = true;
    String colName = "single_value_col";
    FieldSpec spec = new DimensionFieldSpec(colName, DataType.INT, singleValue);
    int numDocs = 20;
    int[] data = new int[numDocs];
    int cardinality = 10;

    File indexDirHeap = new File("/tmp/indexDirHeap");
    FileUtils.forceMkdir(indexDirHeap);
    indexDirHeap.mkdirs();//from   w w w  . j  av  a  2  s  . c om
    File indexDirOffHeap = new File("/tmp/indexDirOffHeap");
    FileUtils.forceMkdir(indexDirOffHeap);
    indexDirOffHeap.mkdirs();
    File bitmapIndexFileOffHeap = new File(indexDirOffHeap,
            colName + V1Constants.Indexes.BITMAP_INVERTED_INDEX_FILE_EXTENSION);
    File bitmapIndexFileHeap = new File(indexDirHeap,
            colName + V1Constants.Indexes.BITMAP_INVERTED_INDEX_FILE_EXTENSION);

    // GENERATE RANDOM DATA SET
    Random r = new Random();
    Map<Integer, Set<Integer>> postingListMap = new HashMap<>();
    for (int i = 0; i < cardinality; i++) {
        postingListMap.put(i, new LinkedHashSet<Integer>());
    }
    for (int i = 0; i < numDocs; i++) {
        data[i] = r.nextInt(cardinality);
        LOGGER.debug("docId:" + i + "  dictId:" + data[i]);
        postingListMap.get(data[i]).add(i);
    }
    for (int i = 0; i < cardinality; i++) {
        LOGGER.debug("Posting list for " + i + " : " + postingListMap.get(i));
    }

    // GENERATE BITMAP USING OffHeapCreator and validate
    OffHeapBitmapInvertedIndexCreator offHeapCreator = new OffHeapBitmapInvertedIndexCreator(indexDirOffHeap,
            cardinality, numDocs, numDocs, spec);
    for (int i = 0; i < numDocs; i++) {
        offHeapCreator.add(i, data[i]);
    }
    offHeapCreator.seal();
    validate(colName, bitmapIndexFileOffHeap, cardinality, postingListMap);

    // GENERATE BITMAP USING HeapCreator and validate
    HeapBitmapInvertedIndexCreator heapCreator = new HeapBitmapInvertedIndexCreator(indexDirHeap, cardinality,
            numDocs, 0, spec);
    for (int i = 0; i < numDocs; i++) {
        heapCreator.add(i, data[i]);
    }
    heapCreator.seal();
    validate(colName, bitmapIndexFileHeap, cardinality, postingListMap);

    // assert that the file sizes and contents are the same
    Assert.assertEquals(bitmapIndexFileHeap.length(), bitmapIndexFileHeap.length());
    Assert.assertTrue(FileUtils.contentEquals(bitmapIndexFileHeap, bitmapIndexFileHeap));

    FileUtils.deleteQuietly(indexDirHeap);
    FileUtils.deleteQuietly(indexDirOffHeap);
}

From source file:net.sourceforge.atunes.kernel.modules.webservices.lastfm.LastFmSubmissionData.java

private synchronized File getSubmissionDataDir() throws IOException {
    if (this.submissionCacheDir == null) {
        this.submissionCacheDir = new File(
                StringUtils.getString(this.osManager.getUserConfigFolder(), this.osManager.getFileSeparator(),
                        Constants.CACHE_DIR, this.osManager.getFileSeparator(), Constants.LAST_FM_CACHE_DIR,
                        this.osManager.getFileSeparator(), Constants.LAST_FM_SUBMISSION_CACHE_DIR));
    }//from   w w  w .j a v  a  2  s  .  c  o m
    if (!this.submissionCacheDir.exists()) {
        FileUtils.forceMkdir(this.submissionCacheDir);
    }
    return this.submissionCacheDir;
}

From source file:io.druid.segment.realtime.firehose.SqlFirehoseFactoryTest.java

@BeforeClass
public static void setup() throws IOException {
    TEST_DIR = File.createTempFile(SqlFirehoseFactoryTest.class.getSimpleName(), "testDir");
    FileUtils.forceDelete(TEST_DIR);/*  w w  w . java 2 s . com*/
    FileUtils.forceMkdir(TEST_DIR);
}

From source file:com.leverno.ysbos.harvest.HarvesterTest.java

private void createTestStructure() {
    rootFolder = new String("/tmp/archiverTest/");
    subFolder = String.format("%s/sub", rootFolder);
    fileOne = new File(String.format("%s/one", rootFolder));
    fileTwo = new File(String.format("%s/two", subFolder));

    try {// w w  w.j  av  a2s.  com
        FileUtils.forceMkdir(new File(subFolder));
        FileUtils.touch(fileOne);
        FileUtils.touch(fileTwo);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

@PostConstruct
public void createCatalogTree() throws IOException {
    final Set<String> applicationNames = getConfiguration().isApplicationAwareCatalog()
            ? collectionAllApplicationNames()
            : Collections.singleton("ignored");
    for (final String applicationName : applicationNames) {
        for (final CatalogSection catalogSection : CatalogSection.values()) {
            FileUtils.forceMkdir(getCatalogSectionDirectory(catalogSection, applicationName));
        }//from   ww w.j  ava2  s . c o m
    }
}