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:com.magnet.tools.tests.MagnetToolStepDefs.java

@When("^I install the magnet server at \"([^\"]*)\" to \"([^\"]*)\"$")
public static void I_install_server(String filePath, String directory) throws Throwable {
    String file = expandVariables(filePath).trim();
    Assert.assertTrue("server zip should exist:" + file, new File(file).exists());
    Assert.assertTrue("server zip should be a file:" + file, new File(file).isFile());
    File dir = new File(expandVariables(directory).trim());
    if (dir.exists()) {
        FileUtils.deleteDirectory(dir);/*  ww w  .  j  a v  a 2 s . co m*/
    }
    if (!dir.mkdir()) {
        ScenarioUtils.log("Directory already exists: " + dir);
    }
    ScenarioUtils.unzip(new File(dir, file), dir);
}

From source file:gov.nih.nci.restgen.util.GeneratorUtil.java

public static void copyDir(String srcFolderStr, String destFolderStr, List<String> excludes)
        throws IOException {
    File srcFolder = new File(srcFolderStr);
    File destFolder = new File(destFolderStr);

    if (srcFolder.isDirectory()) {

        // if directory not exists, create it
        if (!destFolder.exists()) {
            destFolder.mkdir();
            //System.out.println("Directory copied from " + srcFolder + "  to " + destFolder);
        }/*from w w w . ja  v a 2s .  c o  m*/
        FileUtils.copyDirectoryToDirectory(srcFolder, destFolder);
        if (excludes != null && excludes.size() > 0) {
            for (String fileName : excludes) {
                File deleteFile = new File(destFolder + File.separator + fileName);
                FileUtils.deleteQuietly(deleteFile);
            }
        }
    }
}

From source file:com.elastica.helper.FileUtility.java

public static void copyFile(final File srcPath, final File dstPath) throws IOException {

    if (srcPath.isDirectory()) {
        if (!dstPath.exists()) {
            dstPath.mkdir();
        }//w  ww.  j  a v a2s. c o m

        String[] files = srcPath.list();
        for (String file : files) {
            copyFile(new File(srcPath, file), new File(dstPath, file));
        }
    } else {
        if (!srcPath.exists()) {
            throw new IOException("Directory Not Found ::: " + srcPath);
        } else {
            InputStream in = null;
            OutputStream out = null;
            try {
                if (!dstPath.getParentFile().exists()) {
                    dstPath.getParentFile().mkdirs();
                }

                in = new FileInputStream(srcPath);
                out = new FileOutputStream(dstPath);

                // Transfer bytes
                byte[] buf = new byte[1024];
                int len;

                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

                if (out != null) {
                    try {
                        out.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}

From source file:gov.nih.nci.restgen.util.GeneratorUtil.java

public static void copyFiles(String srcFolderStr, String destFolderStr, List exclude) throws IOException {
    File srcFolder = new File(srcFolderStr);
    File destFolder = new File(destFolderStr);

    if (srcFolder.isDirectory()) {

        // if directory not exists, create it
        if (!destFolder.exists()) {
            destFolder.mkdir();
            //System.out.println("Directory copied from " + srcFolder + "  to " + destFolder);
        }//w w w.  j  a  v a2 s . c  o m

        String files[] = srcFolder.list();

        for (String file : files) {
            File srcFile = new File(srcFolder, file);
            if (exclude != null && exclude.contains(srcFile.getName()))
                continue;
            File destFile = new File(destFolder, file);
            copyFile(srcFile, destFile);
        }

    }
}

From source file:edu.iu.kmeans.regroupallgather.KMUtil.java

/**
 * Generate data and upload to the data dir.
 * //from w w  w .j  ava  2  s .c  om
 * @param numOfDataPoints
 * @param vectorSize
 * @param numPointFiles
 * @param localInputDir
 * @param fs
 * @param dataDir
 * @throws IOException
 * @throws InterruptedException
 * @throws ExecutionException
 */
static void generatePoints(int numOfDataPoints, int vectorSize, int numPointFiles, String localInputDir,
        FileSystem fs, Path dataDir) throws IOException, InterruptedException, ExecutionException {
    int pointsPerFile = numOfDataPoints / numPointFiles;
    System.out.println("Writing " + pointsPerFile + " vectors to a file");
    // Check data directory
    if (fs.exists(dataDir)) {
        fs.delete(dataDir, true);
    }
    // Check local directory
    File localDir = new File(localInputDir);
    // If existed, regenerate data
    if (localDir.exists() && localDir.isDirectory()) {
        for (File file : localDir.listFiles()) {
            file.delete();
        }
        localDir.delete();
    }
    boolean success = localDir.mkdir();
    if (success) {
        System.out.println("Directory: " + localInputDir + " created");
    }
    if (pointsPerFile == 0) {
        throw new IOException("No point to write.");
    }
    // Create random data points
    int poolSize = Runtime.getRuntime().availableProcessors();
    ExecutorService service = Executors.newFixedThreadPool(poolSize);
    List<Future<?>> futures = new LinkedList<Future<?>>();
    for (int k = 0; k < numPointFiles; k++) {
        Future<?> f = service
                .submit(new DataGenRunnable(pointsPerFile, localInputDir, Integer.toString(k), vectorSize));
        futures.add(f); // add a new thread
    }
    for (Future<?> f : futures) {
        f.get();
    }
    // Shut down the executor service so that this
    // thread can exit
    service.shutdownNow();
    // Wrap to path object
    Path localInput = new Path(localInputDir);
    fs.copyFromLocalFile(localInput, dataDir);
}

From source file:org.fcrepo.integration.connector.file.AbstractFedoraFileSystemConnectorIT.java

/**
 * Sets a system property and ensures artifacts from previous tests are
 * cleaned up./*  w w w. ja va2s . com*/
 */
@BeforeClass
public static void setSystemPropertiesAndCleanUp() {

    // Instead of creating dummy files over which to federate,
    // we configure the FedoraFileSystemFederation instances to
    // point to paths within the "target" directory.
    final File testDir1 = new File("target/test-classes/config/testing");
    setProperty(PROP_TEST_DIR1, testDir1.getAbsolutePath());

    final File testDir2 = new File("target/test-classes/spring-test");
    cleanUpJsonFilesFiles(testDir2);
    setProperty(PROP_TEST_DIR2, testDir2.getAbsolutePath());

    final File testPropertiesDir = new File("target/test-classes-properties");
    if (testPropertiesDir.exists()) {
        cleanUpJsonFilesFiles(testPropertiesDir);
    } else {
        testPropertiesDir.mkdir();
    }
    setProperty(PROP_EXT_TEST_DIR, testPropertiesDir.getAbsolutePath());
}

From source file:com.seleniumtests.util.FileUtility.java

public static void extractJar(final String storeLocation, final Class<?> clz) throws IOException {
    File firefoxProfile = new File(storeLocation);
    String location = clz.getProtectionDomain().getCodeSource().getLocation().getFile();

    try (JarFile jar = new JarFile(location);) {
        logger.info("Extracting jar file::: " + location);
        firefoxProfile.mkdir();

        Enumeration<?> jarFiles = jar.entries();
        while (jarFiles.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) jarFiles.nextElement();
            String currentEntry = entry.getName();
            File destinationFile = new File(storeLocation, currentEntry);
            File destinationParent = destinationFile.getParentFile();

            // create the parent directory structure if required
            destinationParent.mkdirs();//w  w  w .j a va 2 s.  c o m
            if (!entry.isDirectory()) {
                BufferedInputStream is = new BufferedInputStream(jar.getInputStream(entry));
                int currentByte;

                // buffer for writing file
                byte[] data = new byte[BUFFER];

                // write the current file to disk
                try (FileOutputStream fos = new FileOutputStream(destinationFile);) {
                    BufferedOutputStream destination = new BufferedOutputStream(fos, BUFFER);

                    // read and write till last byte
                    while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
                        destination.write(data, 0, currentByte);
                    }

                    destination.flush();
                    destination.close();
                    is.close();
                }
            }
        }
    }

    FileUtils.deleteDirectory(new File(storeLocation + "\\META-INF"));
    if (OSUtility.isWindows()) {
        new File(storeLocation + "\\" + clz.getCanonicalName().replaceAll("\\.", "\\\\") + ".class").delete();
    } else {
        new File(storeLocation + "/" + clz.getCanonicalName().replaceAll("\\.", "/") + ".class").delete();
    }
}

From source file:hudson.UtilTest.java

/** Creates multiple directories. */
private static void mkdirs(File... dirs) {
    for (File d : dirs) {
        d.mkdir();
        assertTrue(d.getPath(), d.isDirectory());
    }//w  ww.  j  a va2 s. co m
}

From source file:com.frostwire.AzureusStarter.java

private static synchronized void azureusInit() {

    try {//  w ww . ja va  2s.c  om
        if (isAzureusCoreStarted()) {
            LOG.debug("azureusInit(): core already started. skipping.");
            return;
        }
    } catch (Exception ignore) {
    }

    Application.setApplication(
            CommonUtils.getUserSettingsDir().getAbsolutePath() + File.separator + "appwork" + File.separator);
    File jdHome = new File(
            CommonUtils.getUserSettingsDir().getAbsolutePath() + File.separator + "jd_home" + File.separator);
    if (!jdHome.exists()) {
        jdHome.mkdir();
    }
    JDUtilities.setJDHomeDirectory(jdHome);
    JDUtilities.getConfiguration().setProperty("DOWNLOAD_DIRECTORY",
            SharingSettings.TORRENT_DATA_DIR_SETTING.getValue().getAbsolutePath());

    File azureusUserPath = new File(
            CommonUtils.getUserSettingsDir() + File.separator + "azureus" + File.separator);
    if (!azureusUserPath.exists()) {
        azureusUserPath.mkdirs();
    }

    System.setProperty("azureus.loadplugins", "0"); // disable third party azureus plugins
    System.setProperty("azureus.config.path", azureusUserPath.getAbsolutePath());
    System.setProperty("azureus.install.path", azureusUserPath.getAbsolutePath());

    if (!AzureusCoreFactory.isCoreAvailable()) {
        //This does work
        org.gudy.azureus2.core3.util.SystemProperties.APPLICATION_NAME = "azureus";

        org.gudy.azureus2.core3.util.SystemProperties.setUserPath(azureusUserPath.getAbsolutePath());

        if (!SharingSettings.TORRENTS_DIR_SETTING.getValue().exists()) {
            SharingSettings.TORRENTS_DIR_SETTING.getValue().mkdirs();
        }

        COConfigurationManager.setParameter("Auto Adjust Transfer Defaults", false);
        COConfigurationManager.setParameter("General_sDefaultTorrent_Directory",
                SharingSettings.TORRENTS_DIR_SETTING.getValue().getAbsolutePath());

        try {
            AZUREUS_CORE = AzureusCoreFactory.create();
        } catch (AzureusCoreException coreException) {
            //so we already had one eh...
            if (AZUREUS_CORE == null) {
                AZUREUS_CORE = AzureusCoreFactory.getSingleton();
            }
        }

        //to guarantee a synchronous start
        final CountDownLatch signal = new CountDownLatch(1);

        AZUREUS_CORE.addLifecycleListener(new AzureusCoreLifecycleListener() {

            @Override

            public boolean syncInvokeRequired() {
                return false;
            }

            @Override
            public void stopping(AzureusCore core) {
                core.getGlobalManager().pauseDownloads();
            }

            @Override
            public void stopped(AzureusCore core) {
            }

            @Override
            public boolean stopRequested(AzureusCore core) throws AzureusCoreException {
                return false;
            }

            @Override
            public void started(AzureusCore core) {
                signal.countDown();
            }

            @Override
            public boolean restartRequested(AzureusCore core) throws AzureusCoreException {
                return false;
            }

            @Override
            public boolean requiresPluginInitCompleteBeforeStartedEvent() {
                return false;
            }

            @Override
            public void componentCreated(AzureusCore core, AzureusCoreComponent component) {
            }
        });

        if (!AZUREUS_CORE.isStarted() && !AZUREUS_CORE.isRestarting()) {
            AZUREUS_CORE.start();
        }

        AZUREUS_CORE.getGlobalManager().resumeDownloads();

        LOG.debug("azureusInit(): core.start() waiting...");
        try {
            signal.await();
            LOG.debug("azureusInit(): core started...");
        } catch (InterruptedException e) {

            e.printStackTrace();
        }
    }
}

From source file:com.bhbsoft.videoconference.record.convert.util.FlvFileHelper.java

public static File getNewDir(File dir, String name) throws IOException {
    File f = new File(dir, name);
    String baseName = f.getCanonicalPath();

    int recursiveNumber = 0;
    while (f.exists()) {
        f = new File(baseName + "_" + (recursiveNumber++));
    }/*ww w . ja v a 2 s  .c  o  m*/
    f.mkdir();
    return f;
}