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:ddf.security.pdp.xacml.processor.BalanaPdp.java

private void initialize(File xacmlPoliciesDirectory) throws PdpException {
    if (xacmlPoliciesDirectory == null) {
        throw new PdpException(NULL_DIRECTORY_EXCEPTION_MSG);
    }//w w  w.  j a v a 2s .c o m

    try {
        // Only a single default directory is supported
        // If the directory path becomes customizable this
        // functionality should be re-evaluated
        FileUtils.forceMkdir(xacmlPoliciesDirectory);
    } catch (IOException e) {
        LOGGER.error("Unable to create directory: {}", xacmlPoliciesDirectory.getAbsolutePath());
    }
    checkXacmlPoliciesDirectory(xacmlPoliciesDirectory);

    createJaxbContext();

    /**
     * We currently only support one XACML policies directory, but we may support multiple
     * directories in the future.
     */
    xacmlPolicyDirectories = new HashSet<String>(1);
    xacmlPolicyDirectories.add(xacmlPoliciesDirectory.getPath());
    createPdp(createPdpConfig());
}

From source file:com.uwsoft.editor.proxy.ProjectManager.java

private void initWorkspace() {
    try {/*from www . j a v  a 2  s .co m*/
        editorConfigVO = getEditorConfig();
        String myDocPath = Overlap2DUtils.MY_DOCUMENTS_PATH;
        defaultWorkspacePath = myDocPath + File.separator + DEFAULT_FOLDER;
        FileUtils.forceMkdir(new File(defaultWorkspacePath));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:gobblin.service.modules.core.IdentityFlowToJobSpecCompilerTest.java

private void setupDir(String dir) throws Exception {
    FileUtils.forceMkdir(new File(dir));
}

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

@Ignore
@Test/*  w  ww .java2s  . co  m*/
@Category(UnitTest.class)
public void TestserializeUploadedFiles() throws Exception {
    // homeFolder + "/upload/" + jobId + "/" + relPath;
    // Create dummy FGDB

    String jobId = "123-456-789-testosm";
    String wkdirpath = HOME_FOLDER + "/upload/" + jobId;
    File workingDir = new File(wkdirpath);
    FileUtils.forceMkdir(workingDir);
    Assert.assertTrue(workingDir.exists());

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

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

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

    try (OutputStream os = item.getOutputStream()) {
        os.write(testFieldValueBytes);
    }

    File out = new File(wkdirpath + "/buffer.tmp");
    item.write(out);

    List<FileItem> fileItemsList = new ArrayList<>();
    fileItemsList.add(item);
    Assert.assertTrue(out.exists());

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

    //        MultipartSerializer.serializeUploadedFiles(fileItemsList, uploadedFiles, uploadedFilesPaths, wkdirpath);

    Assert.assertEquals("OSM", uploadedFiles.get("dummy1"));
    Assert.assertEquals("dummy1.osm", uploadedFilesPaths.get("dummy1"));

    File content = new File(wkdirpath + "/dummy1.osm");
    Assert.assertTrue(content.exists());

    FileUtils.forceDelete(workingDir);
}

From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java

private void initWorkspace() {
    try {// ww  w.  j a va 2s.  c  o m
        editorConfigVO = getEditorConfig();
        String myDocPath = Overlap2DUtils.MY_DOCUMENTS_PATH;
        workspacePath = myDocPath + "/" + DEFAULT_FOLDER;
        FileUtils.forceMkdir(new File(workspacePath));
        currentWorkingPath = workspacePath;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.alibaba.jstorm.cluster.StormConfig.java

public static String worker_heartbeats_root(Map conf, String id) throws IOException {
    String ret = worker_root(conf, id) + FILE_SEPERATEOR + "heartbeats";
    FileUtils.forceMkdir(new File(ret));
    return ret;/*www .  jav a 2s  .co m*/
}

From source file:com.turn.ttorrent.client.TorrentHandler.java

@Nonnull
private static TorrentByteStorage toStorage(@Nonnull Torrent torrent, @CheckForNull File parent)
        throws IOException {
    if (parent == null)
        throw new NullPointerException("No parent directory given.");

    String parentPath = parent.getCanonicalPath();

    if (!torrent.isMultifile() && parent.isFile())
        return new FileStorage(parent, torrent.getSize());

    List<FileStorage> files = new LinkedList<FileStorage>();
    long offset = 0L;
    for (Torrent.TorrentFile file : torrent.getFiles()) {
        // TODO: Files.simplifyPath() is a security check here to avoid jail-escape.
        // However, it uses "/" not File.separator internally.
        String path = Files.simplifyPath("/" + file.path);
        File actual = new File(parent, path);
        String actualPath = actual.getCanonicalPath();
        if (!actualPath.startsWith(parentPath))
            throw new SecurityException("Torrent file path attempted to break directory jail: " + actualPath
                    + " is not within " + parentPath);

        FileUtils.forceMkdir(actual.getParentFile());
        files.add(new FileStorage(actual, offset, file.size));
        offset += file.size;//from w w  w.j  av a 2 s  .co  m
    }
    return new FileCollectionStorage(files, torrent.getSize());
}

From source file:com.nike.cerberus.operation.dashboard.PublishDashboardOperation.java

private File extractArtifact(final URL artifactUrl) {
    final File extractionDirectory = Files.createTempDir();
    logger.debug("Extracting artifact contents to {}", extractionDirectory.getAbsolutePath());

    ArchiveEntry entry;/* ww  w.j  a  v a  2s. c  om*/
    TarArchiveInputStream tarArchiveInputStream = null;
    try {
        tarArchiveInputStream = new TarArchiveInputStream(
                new GzipCompressorInputStream(artifactUrl.openStream()));
        entry = tarArchiveInputStream.getNextEntry();
        while (entry != null) {
            String entryName = entry.getName();
            if (entry.getName().startsWith("./")) {
                entryName = entry.getName().substring(1);
            }
            final File destPath = new File(extractionDirectory, entryName);
            if (!entry.isDirectory()) {
                final File fileParentDir = new File(destPath.getParent());
                if (!fileParentDir.exists()) {
                    FileUtils.forceMkdir(fileParentDir);
                }
                FileOutputStream fileOutputStream = null;
                try {
                    fileOutputStream = new FileOutputStream(destPath);
                    IOUtils.copy(tarArchiveInputStream, fileOutputStream);
                } finally {
                    IOUtils.closeQuietly(fileOutputStream);
                }
            }
            entry = tarArchiveInputStream.getNextEntry();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(tarArchiveInputStream);
    }

    return extractionDirectory;
}

From source file:com.ipcglobal.fredimport.process.DistinctCategories.java

/**
 * Creates the qlik view sql scripts./*w  w  w  .j a  v a2s .  c om*/
 *
 * @throws Exception the exception
 */
private void createQlikViewSqlScripts() throws Exception {
    final int numFilesSubDir = 100;
    FileOutputStream fop = null;
    String currCategory1Name = "";
    File fileOut = null;
    int fileCnt = 0;
    String subDir = "t2/";
    FileUtils.forceMkdir(new File(outputPathRptSql + subDir));
    // 
    try {
        int xlsRow = 2;
        for (DistinctCategoryItem item : sortedDistinctCategoryItems) {
            String entry = createEntry(xlsRow, item);
            if (!currCategory1Name.equals(item.getCategory1())) {
                if (fop != null)
                    fop.close();
                fileCnt++;
                if ((fileCnt % numFilesSubDir) == 0) {
                    subDir = "t" + xlsRow + "/";
                    FileUtils.forceMkdir(new File(outputPathRptSql + subDir));
                }
                currCategory1Name = item.getCategory1();
                String outPathNameExt = createPathNameExtSqlScript(outputPathRptSql, subDir, currCategory1Name,
                        xlsRow);
                fileOut = new File(outPathNameExt);
                //log.info("Writing to: " + fileOut.getPath() );
                fop = new FileOutputStream(fileOut);
            }
            fop.write(entry.getBytes());
            xlsRow++;
        }
        fop.close();

    } finally {
        if (fop != null)
            fop.close();
    }
}

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

@Test(expected = Exception.class)
@Category(UnitTest.class)
public void TestBuildNativeRequestFgdbOsm() throws Exception {
    String input = "fgdb_osm.zip";
    String jobId = "test-id-123";
    String wkdirpath = homeFolder + "/upload/" + jobId;
    File workingDir = new File(wkdirpath);
    FileUtils.forceMkdir(workingDir);
    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();

    try {//from  ww  w  .  java 2s  . com
        res._buildNativeRequest(jobId, "fgdb_osm", "zip", input, results, zipStat);
    } catch (Exception ex) {
        org.junit.Assert.assertTrue(ex.getMessage().equals("Zip should not contain both osm and ogr types."));
        throw ex;
    }

    FileUtils.forceDelete(workingDir);
}