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.vmware.photon.controller.rootscheduler.helpers.xenon.SchedulerTestEnvironment.java

/**
 * Constructs a test environment object.
 *
 * @throws Throwable Throws an exception if any error is encountered.
 */// w  w  w.  j  a va2  s.com
private SchedulerTestEnvironment(HostClientFactory hostClientFactory, RootSchedulerConfig config,
        ConstraintChecker constraintChecker, CloudStoreHelper cloudStoreHelper, int hostCount)
        throws Throwable {
    assertTrue(hostCount > 0);
    hosts = new PhotonControllerXenonHost[hostCount];
    for (int i = 0; i < hosts.length; i++) {
        String sandbox = generateStorageSandboxPath();
        FileUtils.forceMkdir(new File(sandbox));

        XenonConfig xenonConfig = new XenonConfig();
        xenonConfig.setBindAddress(BIND_ADDRESS);
        xenonConfig.setPort(0);
        xenonConfig.setStoragePath(sandbox);

        hosts[i] = new PhotonControllerXenonHost(xenonConfig, hostClientFactory, null, null, cloudStoreHelper);
        SchedulerServiceGroup schedulerServiceGroup = new SchedulerServiceGroup(config.getRoot(),
                constraintChecker);
        hosts[i].registerScheduler(schedulerServiceGroup);
    }
}

From source file:com.doplgangr.secrecy.FileSystem.storage.java

public static java.io.File getTempFolder() {
    java.io.File tempDir = CustomApp.context.getExternalCacheDir();
    if (tempDir == null) // when all else fails
        tempDir = CustomApp.context.getFilesDir();
    try {// ww w .j  a  v  a  2  s  .c  om
        FileUtils.forceMkdir(tempDir);
    } catch (Exception e) {
        Util.log(e);
    }
    return tempDir;
}

From source file:com.vmware.photon.controller.housekeeper.helpers.dcp.TestEnvironment.java

public TestEnvironment(CloudStoreHelper cloudStoreHelper, HostClientFactory hostClientFactory,
        ServiceConfigFactory serviceConfigFactory, int hostCount) throws Throwable {

    assertTrue(hostCount > 0);//from  w  ww.  j  av a2 s .co m
    hosts = new HousekeeperXenonServiceHost[hostCount];
    for (int i = 0; i < hosts.length; i++) {
        String sandbox = generateStorageSandboxPath();
        FileUtils.forceMkdir(new File(sandbox));

        XenonConfig xenonConfig = new XenonConfig();
        xenonConfig.setBindAddress(BIND_ADDRESS);
        xenonConfig.setPort(0);
        xenonConfig.setStoragePath(sandbox);

        hosts[i] = new HousekeeperXenonServiceHost(xenonConfig, cloudStoreHelper, hostClientFactory,
                serviceConfigFactory);
    }
}

From source file:com.vmware.photon.controller.housekeeper.helpers.xenon.TestEnvironment.java

public TestEnvironment(CloudStoreHelper cloudStoreHelper, HostClientFactory hostClientFactory,
        NsxClientFactory nsxClientFactory, int hostCount, boolean isBackgroudPaused) throws Throwable {

    assertTrue(hostCount > 0);//from w  ww.  j a  va  2 s.  c o m
    hosts = new PhotonControllerXenonHost[hostCount];
    for (int i = 0; i < hosts.length; i++) {
        String sandbox = generateStorageSandboxPath();
        FileUtils.forceMkdir(new File(sandbox));

        XenonConfig xenonConfig = new XenonConfig();
        xenonConfig.setBindAddress(BIND_ADDRESS);
        xenonConfig.setPort(0);
        xenonConfig.setStoragePath(sandbox);

        hosts[i] = new PhotonControllerXenonHost(xenonConfig, hostClientFactory, null, nsxClientFactory,
                cloudStoreHelper);
        HousekeeperServiceGroup housekeeperServiceGroup = new HousekeeperServiceGroup();
        hosts[i].registerHousekeeper(housekeeperServiceGroup);
        SystemConfig.createInstance(hosts[i]);
    }

    TaskSchedulerServiceStateBuilder.triggerInterval = TimeUnit.MILLISECONDS.toMicros(500);
}

From source file:com.destroystokyo.paperclipmavenplugin.GenerateDataMojo.java

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final File patch = new File(generatedResourceLocation, "paperMC.patch");
    final File json = new File(generatedResourceLocation, "patch.json");

    // Create the directory if needed
    if (!generatedResourceLocation.exists()) {
        try {/*  w  ww .ja  va2 s  .  co m*/
            FileUtils.forceMkdir(generatedResourceLocation);
            try {
                FileUtils.forceDelete(patch);
            } catch (FileNotFoundException ignored) {
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Could not create source directory", e);
        }
    }

    if (!vanillaMinecraft.exists()) {
        throw new MojoExecutionException("vanillaMinecraft jar does not exist!");
    }

    if (!paperMinecraft.exists()) {
        throw new MojoExecutionException("paperMinecraft jar does not exist!");
    }

    // Read the files into memory
    getLog().info("Reading jars into memory");
    final byte[] vanillaMinecraftBytes;
    final byte[] paperMinecraftBytes;
    try {
        vanillaMinecraftBytes = Files.readAllBytes(vanillaMinecraft.toPath());
        paperMinecraftBytes = Files.readAllBytes(paperMinecraft.toPath());
    } catch (IOException e) {
        throw new MojoExecutionException("Error reading jars", e);
    }

    getLog().info("Creating patch");
    try (final FileOutputStream paperMinecraftPatch = new FileOutputStream(patch)) {
        Diff.diff(vanillaMinecraftBytes, paperMinecraftBytes, paperMinecraftPatch);
    } catch (InvalidHeaderException | IOException | CompressorException e) {
        throw new MojoExecutionException("Error creating patches", e);
    }

    // Add the SHA-256 hashes for the files
    final MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw new MojoExecutionException("Could not create SHA-256 hasher.", e);
    }

    getLog().info("Hashing files");
    final byte[] vanillaMinecraftHash = digest.digest(vanillaMinecraftBytes);
    final byte[] paperMinecraftHash = digest.digest(paperMinecraftBytes);

    final PatchData data = new PatchData();
    data.setOriginalHash(toHex(vanillaMinecraftHash));
    data.setPatchedHash(toHex(paperMinecraftHash));
    data.setPatch("paperMC.patch");
    data.setSourceUrl("https://s3.amazonaws.com/Minecraft.Download/versions/" + mcVersion + "/minecraft_server."
            + mcVersion + ".jar");

    data.setVersion(mcVersion);

    getLog().info("Writing json file");
    Gson gson = new Gson();
    String jsonString = gson.toJson(data);

    try (final FileOutputStream fs = new FileOutputStream(json);
            final OutputStreamWriter writer = new OutputStreamWriter(fs)) {
        writer.write(jsonString);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

private static void serializeFGDB(List<BodyPart> fileItems, String jobId, Map<String, String> uploadedFiles,
        Map<String, String> uploadedFilesPaths) {
    try {// w w w  .jav a 2  s.c  o m
        Map<String, String> folderMap = new HashMap<>();

        for (BodyPart fileItem : fileItems) {
            String fileName = fileItem.getContentDisposition().getFileName();

            String relPath = FilenameUtils.getPath(fileName);
            if (relPath.endsWith("/")) {
                relPath = relPath.substring(0, relPath.length() - 1);
            }
            fileName = FilenameUtils.getName(fileName);

            String fgdbFolderPath = HOME_FOLDER + "/upload/" + jobId + "/" + relPath;
            boolean isPathSafe = validatePath(HOME_FOLDER + "/upload", fgdbFolderPath);

            if (isPathSafe) {
                String pathVal = folderMap.get(fgdbFolderPath);
                if (pathVal == null) {
                    File folderPath = new File(fgdbFolderPath);
                    FileUtils.forceMkdir(folderPath);
                    folderMap.put(fgdbFolderPath, relPath);
                }

                if (fileName == null) {
                    throw new IOException("File name cannot be null!");
                }

                String uploadedPath = fgdbFolderPath + "/" + fileName;
                boolean isFileSafe = validatePath(fgdbFolderPath, uploadedPath);
                if (isFileSafe) {
                    try (InputStream fileStream = fileItem.getEntityAs(InputStream.class)) {
                        File file = new File(uploadedPath);
                        FileUtils.copyInputStreamToFile(fileStream, file);
                    }
                } else {
                    throw new IOException("Illegal file path:" + uploadedPath);
                }
            } else {
                throw new IOException("Illegal path:" + fgdbFolderPath);
            }
        }

        for (Map.Entry<String, String> pairs : folderMap.entrySet()) {
            String nameOnly = "";
            String fgdbName = pairs.getValue();
            String[] nParts = fgdbName.split("\\.");

            for (int i = 0; i < (nParts.length - 1); i++) {
                if (!nameOnly.isEmpty()) {
                    nameOnly += ".";
                }
                nameOnly += nParts[i];
            }
            uploadedFiles.put(nameOnly, "GDB");
            uploadedFilesPaths.put(nameOnly, fgdbName);
        }
    } catch (Exception e) {
        throw new RuntimeException("Error trying to serialize FGDB!", e);
    }
}

From source file:com.github.marabou.properties.PropertiesLoader.java

private void createUserPropertiesDirectoryIfNonExistent() throws IOException {
    File userPropertiesDirectory = pathHelper.getUserPropertiesDirectory();

    if (!userPropertiesDirectory.exists()) {
        FileUtils.forceMkdir(userPropertiesDirectory);
    }//from  www .  j  a  v  a  2  s . c o  m
}

From source file:com.sonarsource.lits.Dump.java

static void save(List<IssueKey> issues, File dir) {
    try {/*from   w w  w.  jav a 2  s. c om*/
        FileUtils.forceMkdir(dir);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }

    Collections.sort(issues, new IssueKeyComparator());

    PrintStream out = null;
    String prevRuleKey = null;
    String prevComponentKey = null;
    for (IssueKey issueKey : issues) {
        if (!issueKey.ruleKey.equals(prevRuleKey)) {
            if (out != null) {
                endRule(out);
            }
            try {
                out = new PrintStream(new FileOutputStream(new File(dir, ruleKeyToFileName(issueKey.ruleKey))),
                        /* autoFlush: */ true, StandardCharsets.UTF_8.name());
            } catch (IOException e) {
                throw Throwables.propagate(e);
            }
            out.print("{\n");
            startComponent(out, issueKey.componentKey);
        } else if (!issueKey.componentKey.equals(prevComponentKey)) {
            endComponent(out);
            startComponent(out, issueKey.componentKey);
        }
        out.print(issueKey.line + ",\n");
        prevComponentKey = issueKey.componentKey;
        prevRuleKey = issueKey.ruleKey;
    }
    if (out != null) {
        endRule(out);
    }
}

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

public void ensureEmpty() throws FetchException {
    try {/*from   w  w w.  ja  v  a  2 s. c  o  m*/
        if (basedir.exists()) {
            FileUtils.cleanDirectory(basedir);
        } else {
            FileUtils.forceMkdir(basedir);
        }
    } catch (IOException e) {
        throw new FetchException("Unable to ensure directory is empty: " + basedir, e);
    }
}

From source file:com.teotigraphix.caustk.sequencer.SongManager.java

@Override
protected void createProject(Project project) {
    super.createProject(project);
    songDirectory = new File(project.getDirectory(), "songs");
    try {// w ww .  j av a  2 s  . c o  m
        FileUtils.forceMkdir(songDirectory);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    File file = new File(songDirectory, "UntitledSong.ctks");
    trackSong = createTrackSong(file);
    try {
        save();
    } catch (IOException e) {
        e.printStackTrace();
    }
}