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.plugin.excel.xsd.node.store.impl.FileHelper.java

public static File copyFolder(Class clazz, List<String> files, File destination, String rootDirName) {

    File rootDir = null;/*  w w w . j av  a 2  s  . c  o  m*/

    if (clazz != null && files != null && !files.isEmpty()) {

        for (String file : files) {
            InputStream stream = clazz.getClassLoader().getResourceAsStream(file);
            try {
                File temp = new File(destination.getAbsoluteFile() + "/" + file);
                if (!file.contains(".")) {
                    temp.delete();
                    temp.mkdir();
                } else {
                    FileUtils.copyInputStreamToFile(stream, temp);
                }

                if (file.replaceAll("/", "").equalsIgnoreCase(rootDirName)) {
                    rootDir = temp;
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    return rootDir;
}

From source file:net.itransformers.bgpPeeringMap.BgpPeeringMap.java

public static void discover() throws Exception {
    Map<String, String> settings = loadProperties(new File(settingsFile));
    logger.info("Settings" + settings.toString());

    String folderPlaceholder = settings.get("output.dir");

    File outputDir = new File(projectDir + File.separator + folderPlaceholder, label);

    System.out.println(outputDir.getAbsolutePath());
    boolean result = outputDir.mkdir();
    File graphmlDir = new File(outputDir, "undirected");

    result = outputDir.mkdir();//  w  w w .  j av a2s.  com
    XsltTransformer transformer = new XsltTransformer();
    logger.info("SNMP walk start");
    byte[] rawData = snmpWalk(settings);
    logger.info("SNMP walk end");
    File rawDataFile = new File(outputDir, "raw-data-bgpPeeringMap.xml");
    FileUtils.writeStringToFile(rawDataFile, new String(rawData));

    logger.info("Raw-data written to a file in folder " + outputDir);
    logger.info("First-transformation has started with xsltTransformator " + settings.get("xsltFileName1"));

    ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream();
    File xsltFileName1 = new File(projectDir, settings.get("xsltFileName1"));
    ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData);
    transformer.transformXML(inputStream1, xsltFileName1, outputStream1, settings);
    logger.info("First transformation finished");
    File intermediateDataFile = new File(outputDir, "intermediate-bgpPeeringMap.xml");

    FileUtils.writeStringToFile(intermediateDataFile, new String(outputStream1.toByteArray()));
    logger.trace("First transformation output");

    logger.trace(outputStream1.toString());
    logger.info("Second transformation started with xsltTransformator " + settings.get("xsltFileName2"));

    ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream();
    File xsltFileName2 = new File(projectDir, settings.get("xsltFileName2"));
    ByteArrayInputStream inputStream2 = new ByteArrayInputStream(outputStream1.toByteArray());
    transformer.transformXML(inputStream2, xsltFileName2, outputStream2, settings);
    logger.info("Second transformation info");
    logger.trace("Second transformation Graphml output");
    logger.trace(outputStream2.toString());

    ByteArrayInputStream inputStream3 = new ByteArrayInputStream(outputStream2.toByteArray());
    ByteArrayOutputStream outputStream3 = new ByteArrayOutputStream();
    File xsltFileName3 = new File(System.getProperty("base.dir"), settings.get("xsltFileName3"));
    transformer.transformXML(inputStream3, xsltFileName3, outputStream3, null);

    File outputFile = new File(graphmlDir, "undirected-bgpPeeringMap.graphml");
    FileUtils.writeStringToFile(outputFile, new String(outputStream3.toByteArray()));
    logger.info("Output Graphml saved in a file in" + graphmlDir);

    //FileUtils.writeStringToFile(nodesFileListFile, "bgpPeeringMap.graphml");
    FileWriter writer = new FileWriter(new File(outputDir, "undirected" + ".graphmls"), true);
    writer.append("undirected-bgpPeeringMap.graphml").append("\n");
    writer.close();

}

From source file:com.plugin.excel.xsd.node.store.impl.FileHelper.java

public static void copyFolder(File src, File dest) throws IOException {

    if (src.isDirectory()) {

        // if directory not exists, create it
        if (!dest.exists()) {
            dest.mkdir();
            // log.info("Directory copied from " + src + " to " + dest);
        }//  w  w w . j a  va2  s .c  o  m

        // list all the directory contents
        String files[] = src.list();

        for (String file : files) {
            // construct the src and dest file structure
            File srcFile = new File(src, file);
            File destFile = new File(dest, file);
            // recursive copy
            copyFolder(srcFile, destFile);
        }

    } else {
        // if file, then copy it
        // Use bytes stream to support all file types
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dest);

        byte[] buffer = new byte[1024];

        int length;
        // copy the file content in bytes
        while ((length = in.read(buffer)) > 0) {
            out.write(buffer, 0, length);
        }

        in.close();
        out.close();
        // log.info("File copied from " + src + " to " + dest);
    }
}

From source file:com.nullwire.trace.ExceptionHandler.java

/**
 * Search for logfiles./* w  w  w .  java2s .c o  m*/
 * @return
 */
private static String[] searchForLogs() {
    File dir = new File(G.FILES_PATH + "/");
    // Try to create the files folder if it doesn't exist
    dir.mkdir();
    // Filter for ".log" files
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".log");
        }
    };
    return dir.list(filter);
}

From source file:net.sf.sripathi.ws.mock.util.Folder.java

/**
 * Gets the folder information for the path provided.
 * If the folder is not present creates a new folder.
 * /*from  ww w. j a  v  a2 s  . c  o  m*/
 * @param path folder path string.
 * 
 * @return instance of Folder class.
 */
public static Folder getInstance(String path) {

    Folder folder = null;
    Folder.folderMap = new HashMap<String, Folder>();
    Folder.fileSet = new TreeSet<String>();

    try {
        File file = new File(path);

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

        if (!file.isDirectory() && !file.canRead() && !file.canWrite()) {
            throw new MockException("Unable to read dir " + path + " make sure access is set correctly");
        }

        //Get root and sub directories
        folder = new Folder(path, file);

        Folder.folderMap.put(path, folder);

    } catch (Exception e) {
        throw new MockException("Unable to read dir " + path + " make sure access is set correctly");
    }

    return folder;
}

From source file:com.nullwire.trace.ExceptionHandler.java

/**
 * Search for stack trace files.// w  w  w. j a  v a2  s.c om
 * @return
 */
private static String[] searchForStackTraces() {
    File dir = new File(G.FILES_PATH + "/");
    // Try to create the files folder if it doesn't exist
    dir.mkdir();
    // Filter for ".stacktrace" files
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".stacktrace");

        }
    };
    return dir.list(filter);
}

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

/**
 * Expands the zip files and imports the terms therein.
 * //  www  . j ava  2  s . c om
 * @param dir
 */
public static void processZipDir(String dir) {
    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()) {
        try {
            FileUtils.deleteDirectory(outputDir);
        } catch (IOException e) {
            throw new RuntimeException(e); // I hate checked exceptions
        }
    }
    outputDir.mkdir();

    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)));
        }
    }

    // InstanceImporter.runImport(outputDir, (String)null, new
    // DefaultConflictResolver());

    importXmlFiles(outputDir);

    // Versioning.main(new String[]{outputDir.getAbsolutePath()});
}

From source file:edu.isi.webserver.FileUtil.java

static public File downloadFileFromHTTPRequest(HttpServletRequest request) {
    // Download the file to the upload file folder
    File destinationDir = new File(DESTINATION_DIR_PATH);
    logger.info("File upload destination directory: " + destinationDir.getAbsolutePath());
    if (!destinationDir.isDirectory()) {
        destinationDir.mkdir();
    }//from   ww  w  .  ja v  a2s.  c  o m

    DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();

    // Set the size threshold, above which content will be stored on disk.
    fileItemFactory.setSizeThreshold(1 * 1024 * 1024); //1 MB

    //Set the temporary directory to store the uploaded files of size above threshold.
    fileItemFactory.setRepository(destinationDir);

    ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);

    File uploadedFile = null;
    try {
        // Parse the request
        @SuppressWarnings("rawtypes")
        List items = uploadHandler.parseRequest(request);
        @SuppressWarnings("rawtypes")
        Iterator itr = items.iterator();
        while (itr.hasNext()) {
            FileItem item = (FileItem) itr.next();

            // Ignore Form Fields.
            if (item.isFormField()) {
                System.out.println(item.getFieldName());
                System.out.println(item.getString());
                // Do nothing
            } else {
                //Handle Uploaded files. Write file to the ultimate location.
                System.out.println("File field name: " + item.getFieldName());
                uploadedFile = new File(destinationDir, item.getName());
                item.write(uploadedFile);
                System.out.println("File written to: " + uploadedFile.getAbsolutePath());
            }
        }
    } catch (FileUploadException ex) {
        logger.error("Error encountered while parsing the request", ex);
    } catch (Exception ex) {
        logger.error("Error encountered while uploading file", ex);
    }
    return uploadedFile;
}

From source file:fr.paris.lutece.plugins.rss.service.RssGeneratorService.java

/**
 * Creates the pushrss file in the directory
 *
 * @param strRssFileName The file's name that must be deleted
 * @param strRssDocument The content of the new RSS file
 *//*from   w w w  . ja  v  a  2s  .  c o m*/
public static void createFileRss(String strRssFileName, String strRssDocument) {
    FileWriter fileRssWriter;

    try {
        // fetches the pushRss directory path
        String strFolderPath = AppPathService.getPath(RssGeneratorService.PROPERTY_RSS_STORAGE_FOLDER_PATH, "");

        // Test if the pushRss directory exist and create it if it doesn't exist
        if (!new File(strFolderPath).exists()) {
            File fileFolder = new File(strFolderPath);
            fileFolder.mkdir();
        }

        // Creates a temporary RSS file
        String strFileRss = AppPathService.getPath(RssGeneratorService.PROPERTY_RSS_STORAGE_FOLDER_PATH, "")
                + strRssFileName;
        String strFileDirectory = AppPathService.getPath(RssGeneratorService.PROPERTY_RSS_STORAGE_FOLDER_PATH,
                "");
        File fileRss = new File(strFileRss);
        File fileRssDirectory = new File(strFileDirectory);
        File fileRssTemp = File.createTempFile("tmp", null, fileRssDirectory);
        fileRssWriter = new FileWriter(fileRssTemp);
        fileRssWriter.write(strRssDocument);
        fileRssWriter.flush();
        fileRssWriter.close();

        // Deletes the file if the file exists and renames the temporary file into the file
        if (new File(strFileRss).exists()) {
            File file = new File(strFileRss);
            file.delete();
        }

        fileRssTemp.renameTo(fileRss);
    } catch (IOException e) {
        AppLogService.error(e.getMessage(), e);
    } catch (NullPointerException e) {
        AppLogService.error(e.getMessage(), e);
    }
}

From source file:eu.sisob.uma.footils.File.FileFootils.java

private static boolean copyFilesRecusively(final File toCopy, final File destDir) {
    assert destDir.isDirectory();

    if (!toCopy.isDirectory()) {
        return FileFootils.copyFile(toCopy, new File(destDir, toCopy.getName()));
    } else {//from w ww.  j av a2 s .  c  o m
        final File newDestDir = new File(destDir, toCopy.getName());
        if (!newDestDir.exists() && !newDestDir.mkdir()) {
            return false;
        }
        for (final File child : toCopy.listFiles()) {
            if (!FileFootils.copyFilesRecusively(child, newDestDir)) {
                return false;
            }
        }
    }
    return true;
}