Example usage for java.io File mkdirs

List of usage examples for java.io File mkdirs

Introduction

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

Prototype

public boolean mkdirs() 

Source Link

Document

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.

Usage

From source file:de.uniwue.dmir.heatmap.EntryPointIncremental.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) throws IOException, ParseException {

    DateFormat df = new SimpleDateFormat(DATE_FORMAT);
    SimpleDateFormat backupDf = new SimpleDateFormat(BACKUP_DATE_FORMAT);

    String workDir = System.getProperty("workDir", ".");
    LOGGER.debug("Work dir: {}", workDir);
    String configDir = System.getProperty("configDir", ".");
    LOGGER.debug("Config dir: {}", configDir);

    File seedDir = new File(workDir, SEED_DIR);
    LOGGER.debug("Seed dir: {}", seedDir);
    File currentDir = new File(workDir, CURRENT_DIR);
    LOGGER.debug("Current dir: {}", currentDir);
    File backupDir = new File(workDir, BACKUP_DIR);
    LOGGER.debug("Backup dir: {}", backupDir);

    String initialMinTimeString = System.getProperty("minTime");
    LOGGER.debug("Initial minimal time parameter: {}", initialMinTimeString);
    Date initialMinTime = initialMinTimeString == null ? new Date(0) : df.parse(initialMinTimeString);
    LOGGER.debug("Initial minimal time: {}", df.format(initialMinTime));

    String absoluteMaxTimeString = System.getProperty("maxTime");
    LOGGER.debug("Absolute maximal time parameter: {}", absoluteMaxTimeString);
    Date absoluteMaxTime = absoluteMaxTimeString == null ? new Date()
            : new SimpleDateFormat(DATE_FORMAT).parse(absoluteMaxTimeString);
    LOGGER.debug("Absolute maximal time: {}", df.format(absoluteMaxTime));

    String incrementalFile = new File("file:" + configDir, INCREMENTAL_FILE).getPath();
    String settingsFile = new File("file:" + configDir, HEATMAP_PROCESSOR__FILE).getPath();

    LOGGER.debug("Initializing incremental control file: {}", incrementalFile);
    FileSystemXmlApplicationContext incrementalContext = new FileSystemXmlApplicationContext(incrementalFile);

    // get point limit
    int pointLimit = Integer
            .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${point.limit}"));
    LOGGER.debug("Print limit: {}", pointLimit);

    // get backups to keep
    int backupsToKeep = Integer
            .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${backups.to.keep}"));
    LOGGER.debug("Backups to keep: {}", pointLimit);

    LOGGER.debug("Initializing process components (manager and limiter).");
    IProcessManager processManager = incrementalContext.getBean(IProcessManager.class);
    IProcessLimiter processLimiter = incrementalContext.getBean(IProcessLimiter.class);

    LOGGER.debug("Starting incremental loop.");
    while (true) { // break as soon as no new points are available

        // cleanup --- just in case
        LOGGER.debug("Deleting \"current\" dir.");
        FileUtils.deleteDirectory(currentDir);

        // copy from seed to current
        LOGGER.debug("Copying seed.");
        seedDir.mkdirs();
        FileUtils.copyDirectory(seedDir, currentDir);

        // get min time
        LOGGER.debug("Getting minimal time ...");
        Date minTime = initialMinTime;
        ProcessManagerEntry entry = processManager.getEntry();
        if (entry != null && entry.getMaxTime() != null) {
            minTime = entry.getMaxTime();
        }//from ww w .j  a v  a 2s . co  m
        LOGGER.debug("Minimal time: {}", new SimpleDateFormat(DATE_FORMAT).format(minTime));

        // break if we processed all available points (minTime is greater than or equal to absoluteMaxTime)
        if (minTime.getTime() >= absoluteMaxTime.getTime()) {
            LOGGER.debug("Processed all points.");
            break;
        }

        // get the maximal time
        LOGGER.debug("Get maximal time.");

        // get the time from the newest point in our point range (pointMaxTime) ...
        Date pointMaxTime = processLimiter.getMaxTime(minTime, pointLimit);

        // ... and possibly break the loop if no new points are available
        if (pointMaxTime == null)
            break;

        // set the max time and make sure we are not taking to many points 
        // (set max time to the minimum of pointMaxTime and absoluteMaxTime)
        Date maxTime = pointMaxTime.getTime() > absoluteMaxTime.getTime() ? absoluteMaxTime : pointMaxTime;

        LOGGER.debug("Maximal time: {}", new SimpleDateFormat(DATE_FORMAT).format(maxTime));

        // start process
        processManager.start(minTime);

        System.setProperty("minTimestamp", new SimpleDateFormat(DATE_FORMAT).format(minTime));

        System.setProperty("maxTimestamp", new SimpleDateFormat(DATE_FORMAT).format(maxTime));

        FileSystemXmlApplicationContext heatmapContext = new FileSystemXmlApplicationContext(settingsFile);

        IHeatmap heatmap = heatmapContext.getBean(HEATMAP_BEAN, IHeatmap.class);

        ITileProcessor tileProcessor = heatmapContext.getBean(WRITER_BEAN, ITileProcessor.class);

        heatmap.processTiles(tileProcessor);

        tileProcessor.close();
        heatmapContext.close();

        // finish process
        processManager.finish(maxTime);

        // move old seed
        if (backupsToKeep > 0) {
            FileUtils.moveDirectory(seedDir, new File(backupDir, backupDf.format(minTime))); // minTime is the maxTime of the seed

            // cleanup backups
            String[] backups = backupDir.list(DirectoryFileFilter.DIRECTORY);
            File oldestBackup = null;
            if (backups.length > backupsToKeep) {
                for (String bs : backups) {
                    File b = new File(backupDir, bs);
                    if (oldestBackup == null || oldestBackup.lastModified() > b.lastModified()) {
                        oldestBackup = b;
                    }
                }
                FileUtils.deleteDirectory(oldestBackup);
            }

        } else {
            FileUtils.deleteDirectory(seedDir);
        }

        // move new seed
        FileUtils.moveDirectory(currentDir, seedDir);

    }

    incrementalContext.close();

}

From source file:edu.ku.brc.dbsupport.ImportExportDB.java

public static void main(String[] args) {
        Pair<String, String> usernamePassword = UserAndMasterPasswordMgr.getInstance().getUserNamePasswordForDB();
        UIHelper.tryLogin("com.mysql.jdbc.Driver", "org.hibernate.dialect.MySQLDialect", //$NON-NLS-1$ //$NON-NLS-2$
                "testfish", "jdbc:mysql://localhost/testfish", //$NON-NLS-1$ //$NON-NLS-2$
                usernamePassword.first, usernamePassword.second);

        Session testSession = HibernateUtil.getCurrentSession();
        String workingFolder = "Specify6ImportExport"; //$NON-NLS-1$
        File wf = new File(workingFolder);
        if (!wf.exists()) {
            wf.mkdirs();
        }//from  w  ww  .  ja v a2s.c  om
        //String dbTable = "Division"; //$NON-NLS-1$

        ImportExportDB impexp = new ImportExportDB(testSession, workingFolder + File.separator);

        try {
            // record set
            // impexp.importSingleDBObject(dbTable, 1, false);
            // impexp.printRecordSet(dbTable);
            // impexp.printSingleRecordXML(dbTable, 3);
            // impexp.writeRecordSet(dbTable, 1);
            // impexp.writeSingleRecordXML(dbTable, 1);
            // impexp.exportTables();
            // List<String> temp = new ArrayList();
            // impexp.getImmediateParentTables(dbTable,temp , false);
            // impexp.getRequiredFields("Geography");

            // import
            System.out.println("importing..."); //$NON-NLS-1$
            // impexp.importTable(dbTable);
            // impexp.importTable("LoanAgent");
            // print results
            System.out.println("printing..."); //$NON-NLS-1$
            //impexp.printXML(dbTable);
            // impexp.printXML("Geography");
            // impexp.printXML("LoanAgent");
            // impexp.printXML("CollectionObject");
            // impexp.printXML("LoanReturnPreparation");
            // impexp.printXML("CollectionObject");
            // impexp.printXML("Collector");

            // export
            // impexp.writeSingleRecordXML(dbTable,1);
            //impexp.exportTables();

            impexp.writeXMLfile("PrepType"); //$NON-NLS-1$

        } catch (Exception ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex);
            ex.printStackTrace();
        } finally {
            impexp.close();
            System.out.println("...done"); //$NON-NLS-1$
        }
    }

From source file:de.huberlin.cuneiform.main.Main.java

public static void main(String[] args)
        throws ParseException, IOException, NotDerivableException, InterruptedException, JSONException {

    GnuParser gnuParser;/* ww  w . j  av a 2s .  c  om*/
    CommandLine cmdline;
    Options opt;
    String value;
    int platform;
    File outputDir;
    String[] fileList;
    StringBuffer buf;
    String line;
    String dagid;
    File logFile;

    opt = new Options();

    opt.addOption("p", "platform", true, "The platform to perform the Cuneiform script's interpretation. "
            + "Possible platforms are: 'dot', 'local', and 'debug'. Default is 'local'.");

    opt.addOption("d", "directory", true,
            "The output directory, to put the interpretation intermediate and output result as well as the default location to store the log.");

    opt.addOption("c", "clean", false,
            "If set, the execution engine ignores all cached results and starts a clean workflow run.");

    opt.addOption("r", "runid", true,
            "If set, a custom id is set for this workflow run. By default a UUID string is used.");

    opt.addOption("f", "file", true,
            "Override the default location of the log file and use the specified filename instead. If the platform is 'dot', this option sets the name of the output dot-file.");

    opt.addOption("h", "help", false, "Print help text.");

    gnuParser = new GnuParser();
    cmdline = gnuParser.parse(opt, args);

    if (cmdline.hasOption("help")) {

        System.out.println("CUNEIFORM - A Functional Workflow Language\n" + LABEL_VERSION);
        new HelpFormatter().printHelp("java -jar cuneiform.jar [OPTION]*", opt);

        return;
    }

    if (cmdline.hasOption("platform")) {

        value = cmdline.getOptionValue("platform");

        if (value.equals("dot"))
            platform = PLATFORM_DOT;
        else if (value.equals("local"))
            platform = PLATFORM_LOCAL;
        else if (value.equals("debug"))
            platform = PLATFORM_DEBUG;
        else
            throw new RuntimeException("Specified platform '" + value + "' not recognized.");

    } else
        platform = PLATFORM_LOCAL;

    if (cmdline.hasOption('d')) {

        value = cmdline.getOptionValue('d');
    } else
        value = "build";

    outputDir = new File(value);

    if (outputDir.exists()) {

        if (!outputDir.isDirectory())
            throw new IOException(
                    "Output directory '" + outputDir.getAbsolutePath() + "' exists but is not a directory.");

        else if (cmdline.hasOption('c')) {

            FileUtils.deleteDirectory(outputDir);

            if (!outputDir.mkdirs())
                throw new IOException(
                        "Could not create output directory '" + outputDir.getAbsolutePath() + "'");
        }
    } else if (!outputDir.mkdirs())
        throw new IOException("Could not create output directory '" + outputDir.getAbsolutePath() + "'");

    if (cmdline.hasOption('r'))
        dagid = cmdline.getOptionValue('r');
    else
        dagid = UUID.randomUUID().toString();

    if (cmdline.hasOption('f'))
        logFile = new File(cmdline.getOptionValue('f'));
    else
        logFile = null;

    fileList = cmdline.getArgs();
    buf = new StringBuffer();
    if (fileList.length == 0) {

        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {

            while ((line = reader.readLine()) != null)
                buf.append(line).append('\n');
        }

        switch (platform) {

        case PLATFORM_DOT:
            createDot(buf.toString(), outputDir, logFile);
            break;
        case PLATFORM_LOCAL:
            runLocal(buf.toString(), outputDir, logFile, dagid);
            break;
        case PLATFORM_DEBUG:
            runDebug(buf.toString(), outputDir, logFile, dagid);
            break;
        default:
            throw new RuntimeException("Platform not recognized.");
        }
    } else

        switch (platform) {

        case PLATFORM_DOT:
            createDot(fileList, outputDir, logFile);
            break;
        case PLATFORM_LOCAL:
            runLocal(fileList, outputDir, logFile, dagid);
            break;
        case PLATFORM_DEBUG:
            runDebug(fileList, outputDir, logFile, dagid);
            break;
        default:
            throw new RuntimeException("Platform not recognized.");
        }

}

From source file:edu.oregonstate.eecs.mcplan.abstraction.Experiments.java

/**
 * @param args//  ww w .j  av a 2  s . c  om
 * @throws FileNotFoundException
 */
public static void main(final String[] args) throws Exception {
    final String experiment_file = args[0];
    final File root_directory;
    if (args.length > 1) {
        root_directory = new File(args[1]);
    } else {
        root_directory = new File(".");
    }
    final CsvConfigurationParser csv_config = new CsvConfigurationParser(new FileReader(experiment_file));
    final String experiment_name = FilenameUtils.getBaseName(experiment_file);

    final File expr_directory = new File(root_directory, experiment_name);
    expr_directory.mkdirs();

    for (int expr = 0; expr < csv_config.size(); ++expr) {
        final KeyValueStore expr_config = csv_config.get(expr);
        final Configuration config = new Configuration(root_directory.getPath(), experiment_name, expr_config);

        if ("irrelevance".equals(config.domain)) {
            final IrrelevanceDomain domain = new IrrelevanceDomain(config, 10);
            runExperiment(config, domain);
        } else if ("chain_walk".equals(config.domain)) {
            final ChainWalkDomain domain = new ChainWalkDomain(config);
            runExperiment(config, domain);
        } else if ("blackjack".equals(config.domain)) {
            final BlackjackDomain domain = new BlackjackDomain(config);
            runExperiment(config, domain);
        } else if ("taxi".equals(config.domain)) {
            final TaxiDomain domain = new TaxiDomain(config);
            runExperiment(config, domain);
        } else if ("yahtzee".equals(config.domain)) {
            final YahtzeeDomain domain = new YahtzeeDomain(config);
            runExperiment(config, domain);
        } else if ("frogger".equals(config.domain)) {
            final FroggerDomain domain = new FroggerDomain(config);
            runExperiment(config, domain);
        } else if ("racegrid".equals(config.domain)) {
            final RacegridDomain domain = new RacegridDomain(config);
            runExperiment(config, domain);
        } else if ("race_car".equals(config.domain)) {
            final RaceCarDomain domain = new RaceCarDomain(config);
            runExperiment(config, domain);
        } else if ("tamarisk".equals(config.domain)) {
            final TamariskDomain domain = new TamariskDomain(config);
            runExperiment(config, domain);
        } else if ("fuelworld".equals(config.domain)) {
            final FuelWorldDomain domain = new FuelWorldDomain(config);
            runExperiment(config, domain);
        } else if ("cliffworld".equals(config.domain)) {
            final CliffWorldDomain domain = new CliffWorldDomain(config);
            runExperiment(config, domain);
        } else if ("rddl".equals(config.domain)) {
            final RddlDomain domain = new RddlDomain(config);
            runExperiment(config, domain);
        } else {
            throw new IllegalArgumentException("domain = " + config.domain);
        }
    }
}

From source file:com.maxl.java.amikodesk.AMiKoDesk.java

public static void main(String[] args) {

    // Initialize globales
    m_application_data_folder = Utilities.appDataFolder();
    favorite_meds_set = new HashSet<String>();
    favorite_data = new DataStore(m_application_data_folder);
    favorite_meds_set = favorite_data.load(); // HashSet containing registration numbers

    // Register toolkit
    Toolkit tk = Toolkit.getDefaultToolkit();
    tk.addAWTEventListener(WindowSaver.getInstance(m_application_data_folder), AWTEvent.WINDOW_EVENT_MASK);

    // Specify command line options
    Options options = new Options();
    addOption(options, "help", "print this message", false, false);
    addOption(options, "version", "print the version information and exit", false, false);
    addOption(options, "port", "starts AmiKo-server at given port", true, false);
    addOption(options, "width", "sets window width", true, false);
    addOption(options, "height", "sets window height", true, false);
    addOption(options, "lang", "use given language", true, false);
    addOption(options, "type", "start light or full app", true, false);
    addOption(options, "title", "display medical info related to given title", true, false);
    addOption(options, "eancode", "display medical info related to given 13-digit ean-code", true, false);
    addOption(options, "regnr", "display medical info related to given 5-digit registration number", true,
            false);/*from   w ww  .j av a  2  s  . c om*/
    // Activate command line parser
    commandLineParse(options, args);

    // Initialize language files
    if (Utilities.appLanguage().equals("de"))
        m_rb = ResourceBundle.getBundle("amiko_de_CH", new Locale("de", "CH"));
    else if (Utilities.appLanguage().equals("fr"))
        m_rb = ResourceBundle.getBundle("amiko_fr_CH", new Locale("fr", "CH"));

    if (Utilities.appCustomization().equals("desitin")) {
        new SplashWindow(Constants.APP_NAME, 5000);
    } else if (Utilities.appCustomization().equals("meddrugs")) {
        new SplashWindow(Constants.APP_NAME, 5000);
    } else if (Utilities.appCustomization().equals("zurrose")) {
        new SplashWindow(Constants.APP_NAME, 3000);
    }
    // Load javascript
    String jscript_str = FileOps.readFromFile(Constants.JS_FOLDER + "main_callbacks.js");
    m_jscript_str = "<script language=\"javascript\">" + jscript_str + "</script>";

    // Load css style sheet
    m_css_str = "<style>" + FileOps.readFromFile(Constants.CSS_SHEET) + "</style>";

    // Load main database
    m_sqldb = new MainSqlDb();
    // Attempt to load alternative database. if db does not exist, load
    // default database
    // These databases are NEVER zipped!
    if (m_sqldb.loadDBFromPath(m_application_data_folder + "\\" + Constants.DEFAULT_AMIKO_DB_BASE
            + Utilities.appLanguage() + ".db") == 0) {
        System.out.println("Loading default amiko database");
        if (Utilities.appLanguage().equals("de"))
            m_sqldb.loadDB("de");
        else if (Utilities.appLanguage().equals("fr"))
            m_sqldb.loadDB("fr");
    }

    // Load rose database
    if (Utilities.appCustomization().equals("zurrose")) {
        m_rosedb = new RoseSqlDb();
        if (m_rosedb.loadDBFromPath(m_application_data_folder + "\\" + Constants.DEFAULT_ROSE_DB) == 0) {
            System.out.println("Loading default rose db");
            m_rosedb.loadDB();
        }
    }

    // Initialize update class
    m_maindb_update = new UpdateDb(m_sqldb);

    // Create shop folder in application data folder
    File wdir = new File(m_application_data_folder + "\\shop");
    if (!wdir.exists())
        wdir.mkdirs();

    // Load interaction cart
    m_interactions_cart = new InteractionsCart();

    // Create shopping cart and load related files
    m_shopping_cart = new ShoppingCart();
    loadAuthors();
    m_emailer = new Emailer(m_rb);

    // Create comparison cart and load related files
    m_comparison_cart = new ComparisonCart();

    // Preferences
    m_prefs = Preferences.userRoot().node(SettingsPage.class.getName());

    // UIUtils.setPreferredLookAn dFeel();
    NativeInterface.open();
    NativeSwing.initialize();

    // Setup font size based on screen size
    UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("Dialog", Font.PLAIN, 14));
    UIManager.put("Label.font", new Font("Dialog", Font.PLAIN, 12));
    UIManager.put("CheckBox.font", new Font("Dialog", Font.PLAIN, 12));
    UIManager.put("Button.font", new Font("Dialog", Font.BOLD, 14));
    UIManager.put("ToggleButton.font", new Font("Dialog", Font.BOLD, 14));
    UIManager.put("ToggleButton.select", m_selected_but_color);
    UIManager.put("Menu.font", new Font("Dialog", Font.PLAIN, 12));
    UIManager.put("MenuBar.font", new Font("Dialog", Font.PLAIN, 12));
    UIManager.put("MenuItem.font", new Font("Dialog", Font.PLAIN, 12));
    UIManager.put("ToolBar.font", new Font("Dialog", Font.PLAIN, 12));

    // Schedule a job for the event-dispatching thread:
    // creating and showing this application's GUI
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            if (!commandLineOptionsProvided()) {
                System.out.println("No relevant command line options provided... creating full GUI");
                createAndShowFullGUI();
            } else if (CML_OPT_TYPE.equals("full")) {
                System.out.println("Creating full GUI");
                createAndShowFullGUI();
            } else if (CML_OPT_TYPE.equals("light")) {
                System.out.println("Creating light GUI");
                createAndShowLightGUI();
            }
        }
    });

    NativeInterface.runEventPump();
}

From source file:Main.java

/**
 * Creates the directory named by this file, creating missing parent
 * directories if necessary./*from   w  w  w .ja va  2  s.c  o m*/
 * 
 * @param tree
 *            The directory name by this file
 */
public static void createTree(File tree) {
    tree.mkdirs();
}

From source file:Main.java

public static String makeDir(String str) {
    String s = Environment.getExternalStorageDirectory().getAbsolutePath() + str;
    File dir = new File(s);
    dir.mkdirs();

    return s;/*from   w w w. j a  v a 2  s  .  c om*/
}

From source file:Main.java

public static boolean createDirectory(String path) {
    File file = new File(path);
    return file.mkdirs();
}

From source file:Main.java

public static File mkdir(String dirPath) {
    if (dirPath == null) {
        return null;
    }/* www  .j ava 2 s. c  om*/
    File dir = new File(dirPath);
    dir.mkdirs();
    return dir;
}

From source file:Main.java

public static boolean makeDirectory(String dirPath) {
    File file = new File(dirPath);
    return file.mkdirs() || file.isDirectory();
}