Example usage for java.io File mkdir

List of usage examples for java.io File mkdir

Introduction

In this page you can find the example usage for java.io File mkdir.

Prototype

public boolean mkdir() 

Source Link

Document

Creates the directory named by this abstract pathname.

Usage

From source file:de.rub.syssec.saaf.analysis.steps.extract.ApkUnzipper.java

/**
 * Extracts the given archive into the given destination directory
 * /*  ww w  . j  a v  a2s  .co  m*/
 * @param archive
 *            - the file to extract
 * @param dest
 *            - the destination directory
 * @throws Exception
 */
public static void extractArchive(File archive, File destDir) throws IOException {

    if (!destDir.exists()) {
        destDir.mkdir();
    }

    ZipFile zipFile = new ZipFile(archive);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();

    byte[] buffer = new byte[16384];
    int len;
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();

        String entryFileName = entry.getName();

        File dir = buildDirectoryHierarchyFor(entryFileName, destDir);
        if (!dir.exists()) {
            dir.mkdirs();
        }

        if (!entry.isDirectory()) {

            File file = new File(destDir, entryFileName);

            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));

            BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));

            while ((len = bis.read(buffer)) > 0) {
                bos.write(buffer, 0, len);
            }

            bos.flush();
            bos.close();
            bis.close();
        }
    }
    zipFile.close();
}

From source file:com.loy.MicroServiceConsole.java

@SuppressWarnings("rawtypes")
static void init() {

    ClassPathResource classPathResource = new ClassPathResource("application.yml");
    Yaml yaml = new Yaml();
    Map result = null;//  ww  w  .  j av  a2 s. c  o  m
    try {
        result = (Map) yaml.load(classPathResource.getInputStream());
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    String platformStr = result.get("platform").toString();
    String version = result.get("version").toString();
    String jvmOption = result.get("jvmOption").toString();
    @SuppressWarnings("unchecked")
    List<String> projects = (List<String>) result.get("projects");
    platform = Platform.valueOf(platformStr);

    final Runtime runtime = Runtime.getRuntime();
    File pidsForder = new File("./pids");
    if (!pidsForder.exists()) {
        pidsForder.mkdir();
    } else {
        File[] files = pidsForder.listFiles();
        if (files != null) {
            for (File f : files) {
                f.deleteOnExit();
                String pidStr = f.getName();
                try {
                    Long pid = new Long(pidStr);
                    if (Processes.isProcessRunning(platform, pid)) {
                        if (Platform.Windows == platform) {
                            Processes.tryKillProcess(null, platform, new NullProcessor(), pid);
                        } else {
                            Processes.killProcess(null, platform, new NullProcessor(), pid);
                        }

                    }
                } catch (Exception ex) {
                }
            }
        }
    }

    File currentForder = new File("");
    String root = currentForder.getAbsolutePath();
    root = root.replace(File.separator + "build" + File.separator + "libs", "");
    root = root.replace(File.separator + "e-example-ms-start", "");
    final String rootPath = root;
    new Thread(new Runnable() {
        @Override
        public void run() {
            int size = projects.size();
            int index = 1;
            for (String value : projects) {
                String path = value;
                String[] values = value.split("/");
                value = values[values.length - 1];
                value = rootPath + "/" + path + "/build/libs/" + value + "-" + version + ".jar";
                final String command = value;
                try {
                    Process process = runtime
                            .exec("java " + jvmOption + " -Dfile.encoding=UTF-8 -jar " + command);
                    Long pid = Processes.processId(process);
                    pids.add(pid);
                    File pidsFile = new File("./pids", pid.toString());
                    pidsFile.createNewFile();
                    new WriteLogThread(process.getInputStream()).start();

                } catch (IOException e) {
                    e.printStackTrace();
                }
                synchronized (lock) {
                    try {
                        if (index < size) {
                            lock.wait();
                        } else {
                            index++;
                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }).start();
}

From source file:com.runwaysdk.dataaccess.io.instance.VersioningUnzipper.java

/**
 * Expands the zip files and imports the terms therein.
 * //from   w w  w.  j ava2  s . co m
 * @param dir
 */
public static void processZipDir(String dir) {
    try {
        File directory = new File(dir);

        if (!directory.exists()) {
            logger.error("Directory [" + directory.getAbsolutePath() + "] does not exist, aborting import.");

            return;
        }

        final File outputDir = new File(dir + TEMP_DIR);

        if (outputDir.exists()) {
            FileUtils.deleteDirectory(outputDir);
        }

        outputDir.mkdir();

        try {

            for (File zip : directory.listFiles()) {
                if (zip.getName().endsWith(".gz")) {
                    logger.info("Unzipping " + zip.getAbsolutePath() + " to " + outputDir + ".");

                    FileIO.gunzip(zip,
                            new File(outputDir, zip.getName().substring(0, zip.getName().length() - 3)));
                }
            }

            DatabaseVersioning.main(new String[] { outputDir.getAbsolutePath() });
        } finally {
            FileUtils.deleteDirectory(outputDir);
        }
    } catch (IOException e) {
        throw new ProgrammingErrorException(e);
    }
}

From source file:com.googlecode.promnetpp.research.main.CompareOutputMain.java

private static void doSeedRun(int seed) throws IOException, InterruptedException {
    System.out.println("Running with seed " + seed);
    String pattern = "int random = <INSERT_SEED_HERE>;";
    int start = sourceCode.indexOf(pattern);
    int end = start + pattern.length();
    String line = sourceCode.substring(start, end);
    line = line.replace("<INSERT_SEED_HERE>", Integer.toString(seed));
    String sourceCodeWithSeed = sourceCode.replace(pattern, line);
    File tempFile = new File("temp.pml");
    FileUtils.writeStringToFile(tempFile, sourceCodeWithSeed);
    //Create a "project" folder
    String fileNameWithoutExtension = fileName.split("[.]")[0];
    File folder = new File("test1-" + fileNameWithoutExtension);
    if (folder.exists()) {
        FileUtils.deleteDirectory(folder);
    }/*ww  w  .j  a v a  2  s.  com*/
    folder.mkdir();
    //Copy temp.pml to our new folder
    FileUtils.copyFileToDirectory(tempFile, folder);
    //Simulate the model using Spin
    List<String> spinCommand = new ArrayList<String>();
    spinCommand.add(GeneralData.spinHome + "/spin");
    spinCommand.add("-u1000000");
    spinCommand.add("temp.pml");
    ProcessBuilder processBuilder = new ProcessBuilder(spinCommand);
    processBuilder.directory(folder);
    processBuilder.redirectOutput(new File(folder, "spin-" + seed + ".txt"));
    Process process = processBuilder.start();
    process.waitFor();
    //Translate via PROMNeT++
    List<String> PROMNeTppCommand = new ArrayList<String>();
    PROMNeTppCommand.add("java");
    PROMNeTppCommand.add("-enableassertions");
    PROMNeTppCommand.add("-jar");
    PROMNeTppCommand.add("\"" + GeneralData.getJARFilePath() + "\"");
    PROMNeTppCommand.add("temp.pml");
    processBuilder = new ProcessBuilder(PROMNeTppCommand);
    processBuilder.directory(folder);
    processBuilder.environment().put("PROMNETPP_HOME", GeneralData.PROMNeTppHome);
    process = processBuilder.start();
    process.waitFor();
    //Run opp_makemake
    FileUtils.copyFileToDirectory(new File("opp_makemake.bat"), folder);
    List<String> makemakeCommand = new ArrayList<String>();
    if (Utilities.operatingSystemType.equals("windows")) {
        makemakeCommand.add("cmd");
        makemakeCommand.add("/c");
        makemakeCommand.add("opp_makemake.bat");
    } else {
        throw new RuntimeException("Support for Linux/OS X not implemented" + " here yet.");
    }
    processBuilder = new ProcessBuilder(makemakeCommand);
    processBuilder.directory(folder);
    process = processBuilder.start();
    process.waitFor();
    //Run make
    FileUtils.copyFileToDirectory(new File("opp_make.bat"), folder);
    List<String> makeCommand = new ArrayList<String>();
    if (Utilities.operatingSystemType.equals("windows")) {
        makeCommand.add("cmd");
        makeCommand.add("/c");
        makeCommand.add("opp_make.bat");
    } else {
        throw new RuntimeException("Support for Linux/OS X not implemented" + " here yet.");
    }
    processBuilder = new ProcessBuilder(makeCommand);
    processBuilder.directory(folder);
    process = processBuilder.start();
    process.waitFor();
    System.out.println(Utilities.getStreamAsString(process.getInputStream()));
    System.exit(1);
}

From source file:com.smart.common.FileHelper.java

/**
 * ?/*from  ww w  .j ava  2  s  .  c o m*/
 *
 * @param filePath 
 * @param isCreate ?
 * @return
 * @throws java.lang.Exception
 */
public static boolean CheckFileExist(String filePath, boolean isCreate) throws Exception {
    try {
        File file = new File(filePath);
        if (!file.exists()) {
            if (isCreate) {
                file.mkdir();
            }
            return false;
        } else {
            return true;
        }
    } catch (Exception e) {
        throw new Exception(e.getLocalizedMessage());
    }
}

From source file:com.googlecode.osde.internal.igoogle.IgAddItJob.java

static File getOsdeWorkFolder() {
    String userHome = System.getProperty("user.home");
    File osdeWorkFolder = new File(userHome, Activator.WORK_DIR_NAME);
    if (!osdeWorkFolder.exists()) {
        osdeWorkFolder.mkdir();
    }/* w w w .j  a v a2 s.  com*/
    return osdeWorkFolder;
}

From source file:com.splunk.shuttl.testutil.TUtilsFile.java

private static void createDirectory(File dir) {
    if (!dir.mkdir())
        TUtilsTestNG.failForException("Could not create directory: " + dir.getAbsolutePath(),
                new RuntimeException());
    try {/*from  w ww .j a v a  2s  . c  o m*/
        FileUtils.forceDeleteOnExit(dir);
    } catch (IOException e) {
        TUtilsTestNG.failForException("Could not force delete on exit: " + dir.getAbsolutePath(),
                new RuntimeException(e));
    }
}

From source file:de.flapdoodle.embedmongo.Files.java

public static File createOrCheckDir(String dir) throws IOException {
    File tempFile = new File(dir);
    if ((tempFile.exists()) && (tempFile.isDirectory()))
        return tempFile;
    if (!tempFile.mkdir())
        throw new IOException("Could not create Tempdir: " + tempFile);
    return tempFile;
}

From source file:com.edduarte.protbox.core.Constants.java

/**
 * Moves all contents from the first specified registry to the second specified
 * registry, overriding if it already exists!
 *///from  w  w w  .  ja  va 2 s. c om
public static void moveContentsFromDirToDir(File fromDir, File toDir) throws IOException {
    try {
        File[] list = fromDir.listFiles();
        if (list == null) {
            return;
        }
        for (File f : list) {
            File destination = new File(toDir, f.getName());
            if (f.isDirectory()) {
                destination.mkdir();
                moveContentsFromDirToDir(f, destination);
            } else {
                FileUtils.writeByteArrayToFile(destination, FileUtils.readFileToByteArray(f));
            }
            Constants.delete(f);
        }
    } catch (NullPointerException ex) {
        throw new IOException("Specified registry is not a folder.", ex);
    }
}

From source file:com.splout.db.common.TestUtils.java

/**
 * Creates a simple database with two columns: one integer (a) and one string (b). It also insertes one default row
 * from parameters a, b.//  www .  j a  v a  2s .c om
 *
 * @throws EngineException
 */
public static void createFooDatabase(String where, int a, String b)
        throws SQLException, JSONSerDeException, ClassNotFoundException, EngineException {
    File dbFolder = new File(where);
    dbFolder.mkdir();
    final SQLite4JavaManager manager = new SQLite4JavaManager();
    SploutConfiguration testConfig = SploutConfiguration.getTestConfig();
    manager.init(new File(where + "/" + "foo.db"), testConfig, null);
    manager.query("DROP TABLE IF EXISTS t;", 100);
    manager.query("CREATE TABLE t (a INT, b TEXT);", 100);
    manager.query("INSERT INTO t (a, b) VALUES (" + a + ", \"" + b + "\")", 100);
    manager.close();
}