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:net.mindengine.galen.tests.specs.reader.PageSpecsReaderTest.java

@BeforeClass
public void init() throws IOException {
    FileUtils.forceMkdir(new File(TEST_FOLDER));
}

From source file:cpcc.demo.setup.builder.SquareDemoBuilder.java

/**
 * @param outputDirectory the output folder.
 * @throws IOException in case of errors.
 * @throws JsonProcessingException in case of errors.
 *///from   www  . j av  a 2  s .  c o  m
public void write(File outputDirectory) throws IOException, JsonProcessingException {
    FileUtils.forceMkdir(outputDirectory);

    List<RealVehicle> rvs = new ArrayList<>();
    rvs.add(setUpGroundStation(1));
    rvs.addAll(IntStream
            .range(0, nrCellsWide).mapToObj(x -> IntStream.range(0, nrCellsHigh)
                    .mapToObj(y -> setupRealVehicle(x, y)).collect(Collectors.toList()))
            .flatMap(List::stream).collect(Collectors.toList()));

    new GlobalSetupWriter().write(new File(outputDirectory, "db-setup-all.sql"), rvs);

    rvs.stream().forEach(rethrowConsumer(x -> new RealVehicleBasicWriter(pm.getBasePort())
            .write(new File(outputDirectory, "db-setup-" + x.getName() + "-rv.sql"), x)));

    rvs.stream().forEach(rethrowConsumer(x -> new RealVehicleCameraWriter()
            .write(new File(outputDirectory, "db-setup-" + x.getName() + "-cam.sql"), x)));
}

From source file:appeng.services.export.MinecraftItemCSVExporter.java

@Override
public void export() {
    final Iterable<Item> items = this.itemRegistry.typeSafeIterable();
    final List<Item> itemList = Lists.newArrayList(items);

    final List<String> lines = Lists.transform(itemList,
            new ItemRowExtractFunction(this.itemRegistry, this.mode));

    final Joiner newLineJoiner = Joiner.on('\n');
    final Joiner newLineJoinerIgnoringNull = newLineJoiner.skipNulls();
    final String joined = newLineJoinerIgnoringNull.join(lines);

    final File file = new File(this.exportDirectory, ITEM_CSV_FILE_NAME);

    try {//  ww w  .  j a  v  a2  s . c o  m
        FileUtils.forceMkdir(this.exportDirectory);

        final Writer writer = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8")));

        final String header = this.mode == ExportMode.MINIMAL ? MINIMAL_HEADER : VERBOSE_HEADER;
        writer.write(header);
        writer.write("\n");
        writer.write(joined);
        writer.flush();
        writer.close();

        AELog.info(EXPORT_SUCCESSFUL_MESSAGE, lines.size(), ITEM_CSV_FILE_NAME);
    } catch (final IOException e) {
        AELog.warn(EXPORT_UNSUCCESSFUL_MESSAGE);
        AELog.debug(e);
    }
}

From source file:me.springframework.di.gen.factory.FileSystemDestination.java

public Writer getWriter() throws IOException {
    try {//www.  j  a  v a2s . c o  m
        File destination = getFile();
        FileUtils.forceMkdir(destination.getParentFile());
        return new FileWriter(destination);
    } catch (IOException e) {
        throw new GeneratorException(e);
    }
}

From source file:com.dianping.maven.plugin.tools.wms.WorkspaceManagementServiceImpl.java

private void generateContainerProject(WorkspaceContext context) throws WorkspaceManagementException {
    File projectBase = new File(context.getBaseDir(), "phoenix-container");
    File sourceFolder = new File(projectBase, "src/main/java");
    File resourceFolder = new File(projectBase, "src/main/resources");
    File webinfFolder = new File(projectBase, "src/main/webapp/WEB-INF");
    try {/*w w w. ja  v a 2 s  .c om*/
        FileUtils.forceMkdir(sourceFolder);
        FileUtils.forceMkdir(resourceFolder);
        FileUtils.forceMkdir(webinfFolder);

        FileUtils.copyFileToDirectory(FileUtils.toFile(this.getClass().getResource("/byteman-2.1.2.jar")),
                resourceFolder);

        // web.xml
        ContainerWebXMLGenerator containerWebXMLGenerator = new ContainerWebXMLGenerator();
        containerWebXMLGenerator.generate(new File(webinfFolder, "web.xml"), null);

        // pom.xml
        ContainerPomXMLGenerator containerPomXMLGenerator = new ContainerPomXMLGenerator();
        Map<String, String> containerPomXMLGeneratorContext = new HashMap<String, String>();
        containerPomXMLGeneratorContext.put("phoenixRouterVersion", context.getPhoenixRouterVersion());
        containerPomXMLGenerator.generate(new File(projectBase, "pom.xml"), containerPomXMLGeneratorContext);

        // BizServer.java
        ContainerBizServerGenerator containerBizServerGenerator = new ContainerBizServerGenerator();
        containerBizServerGenerator
                .generate(new File(sourceFolder, "com/dianping/phoenix/container/BizServer.java"), null);

        context.setBootstrapProjectDir(projectBase);
    } catch (Exception e) {
        throw new WorkspaceManagementException(e);
    }
}

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

@Test
@Category(UnitTest.class)
public void TestserializeUploadedFiles() throws Exception {
    //homeFolder + "/upload/" + jobId + "/" + relPath;
    // Create dummy FGDB

    String jobId = "123-456-789-testosm";
    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, "dummy1.osm");

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

    OutputStream os = item.getOutputStream();
    os.write(testFieldValueBytes);//from w  w w . j  a v  a  2 s  .  co  m
    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._serializeUploadedFiles(fileItemsList, jobId, uploadedFiles, uploadedFilesPaths, wkdirpath);

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

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

    FileUtils.forceDelete(workingDir);
}

From source file:edu.uci.ics.pregelix.example.dataload.AsterixDataLoadTest.java

public void setUp(String storePath) throws Exception {
    ClusterConfig.setStorePath(storePath);
    ClusterConfig.setClusterPropertiesPath(PATH_TO_CLUSTER_PROPERTIES);
    ClusterConfig.clearConnection();/*from w  ww. java2 s .c  o m*/
    cleanupStores();
    PregelixHyracksIntegrationUtil.init();
    LOGGER.info("Hyracks mini-cluster started");
    FileUtils.forceMkdir(new File(ACTUAL_RESULT_DIR));
    FileUtils.cleanDirectory(new File(ACTUAL_RESULT_DIR));

    IOptimizer dynamicOptimizer = new NoOpOptimizer();
    giraphTestJobGen = new JobGenOuterJoin(job, dynamicOptimizer);
}

From source file:com.ibm.liberty.starter.api.v1.LibertyFileUploader.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String tech = request.getParameter(PARAMETER_TECH);
    String workspaceId = request.getParameter(PARAMETER_WORKSPACE); //specify the unique workspace directory to upload the file(s) to.   
    Collection<Part> filePartCollection = request.getParts();

    String serverHostPort = request.getRequestURL().toString().replace(request.getRequestURI(), "");
    int schemeLength = request.getScheme().toString().length();
    String internalHostPort = "http" + serverHostPort.substring(schemeLength);
    log.log(Level.FINER, "serverHostPort : " + serverHostPort);
    final ServiceConnector serviceConnector = new ServiceConnector(serverHostPort, internalHostPort);
    HashMap<Part, String> fileNames = new HashMap<Part, String>();
    if (!isValidRequest(request, response, tech, workspaceId, filePartCollection, serviceConnector,
            fileNames)) {//  w w w  .j a  va  2  s  .co m
        return;
    }

    Service techService = serviceConnector.getServiceObjectFromId(tech);
    String techDirPath = StarterUtil.getWorkspaceDir(workspaceId) + "/" + techService.getId();
    File techDir = new File(techDirPath);
    if (techDir.exists() && techDir.isDirectory()
            && "true".equalsIgnoreCase(request.getParameter(PARAMETER_CLEANUP))) {
        FileUtils.cleanDirectory(techDir);
        log.log(Level.FINER, "Cleaned up tech workspace directory : " + techDirPath);
    }

    for (Part filePart : filePartCollection) {
        if (!techDir.exists()) {
            FileUtils.forceMkdir(techDir);
            log.log(Level.FINER, "Created tech directory :" + techDirPath);
        }

        String filePath = techDirPath + "/" + fileNames.get(filePart);
        log.log(Level.FINER, "File path : " + filePath);
        File uploadedFile = new File(filePath);

        Files.copy(filePart.getInputStream(), uploadedFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        log.log(Level.FINE, "Copied file to " + filePath);
    }

    if ("true".equalsIgnoreCase(request.getParameter(PARAMETER_PROCESS))) {
        // Process uploaded file(s)
        String processResult = serviceConnector.processUploadedFiles(techService, techDirPath);
        if (!processResult.equalsIgnoreCase("success")) {
            log.log(Level.INFO,
                    "Error processing the files uploaded to " + techDirPath + " : Result=" + processResult);
            response.sendError(500, processResult);
            return;
        }
        log.log(Level.FINE, "Processed the files uploaded to " + techDirPath);
    }

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("success");
    out.close();
}

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

public static String worker_root(Map conf, String id) throws IOException {
    String ret = worker_root(conf) + FILE_SEPERATEOR + id;
    FileUtils.forceMkdir(new File(ret));
    return ret;/*from   w w w.  j  a v a  2  s.  co  m*/
}

From source file:com.yahoo.sshd.authentication.file.TestPKUpdating.java

private void buildSshDirs(File homeDir, User[] dirs) throws IOException {
    for (User user : dirs) {
        File userDir = new File(homeDir, user.name);
        File sshDir = new File(userDir, ".ssh");
        File authKeys = new File(sshDir, "authorized_keys");

        FileUtils.forceMkdir(sshDir);

        // give them public keys
        FileUtils.copyFile(user.publicKey, authKeys);
    }//from ww w .jav  a 2 s . c  o m
}