List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:com.mpobjects.rtcalltree.report.xml.XmlReporter.java
/** * @param aCreationDate//from w w w . j av a 2 s .c o m * @param aThreadName * @return */ protected Writer createWriter(Date aCreationDate, String aThreadName) { String filename = MessageFormat.format(filenamePattern, aCreationDate, aThreadName); filename = filename.replaceAll("[: _]+", "_"); File outfile = new File(destination, filename); try { FileUtils.forceMkdir(outfile.getParentFile()); LOG.debug("Writing XML report to {}", outfile.toString()); return new OutputStreamWriter(new FileOutputStream(outfile), Charsets.UTF_8); } catch (IOException e) { LOG.error("Unable to create file output stream for: " + outfile.toString() + ". " + e.getMessage(), e); return null; } }
From source file:com.github.signed.sandboxes.maven.MyMojo.java
private void findLicenseInformation(Artifact artifact, File file) throws net.lingala.zip4j.exception.ZipException, IOException { getLog().info(artifact.getId());/*from w w w. j a v a2 s . c om*/ MavenProject mavenProjectForArtifact = buildProjectFrom(artifact); List<License> licenses = mavenProjectForArtifact.getLicenses(); boolean isCDDL = false; for (License license : licenses) { isCDDL = isCDDL || StringUtils.containsIgnoreCase(license.getName(), "cddl"); } if (!isCDDL) { return; } String sub = artifact.getGroupId().replaceAll("\\.", "/") + "/" + artifact.getArtifactId() + "/" + artifact.getVersion(); final File artifactDirectory = new File(outputDirectory, sub); FileUtils.forceMkdir(artifactDirectory); final SingleFileUnzip unzip = new SingleFileUnzip(artifact.getFile()); zipDumper.dumpZipContent(file, new LegalRelevantFiles() { @Override public void licenseFile(FileHeader license) { getLog().info(license.getFileName()); unzip.unzip(license, artifactDirectory); } @Override public void noticeFile(FileHeader notice) { getLog().info(notice.getFileName()); unzip.unzip(notice, artifactDirectory); } }); }
From source file:com.googlecode.jmxtrans.model.output.RRDWriter.java
/** * If the database file doesn't exist, it'll get created, otherwise, it'll * be returned in r/w mode.//www . ja v a 2 s. c om */ protected RrdDb createOrOpenDatabase() throws Exception { RrdDb result; if (!this.outputFile.exists()) { FileUtils.forceMkdir(this.outputFile.getParentFile()); RrdDefTemplate t = new RrdDefTemplate(this.templateFile); t.setVariable("database", this.outputFile.getCanonicalPath()); RrdDef def = t.getRrdDef(); result = new RrdDb(def); } else { result = new RrdDb(this.outputFile.getCanonicalPath()); } return result; }
From source file:ml.shifu.shifu.core.alg.SVMTrainer.java
private void saveModel() { File folder = new File("./models"); if (!folder.exists()) { try {/*ww w . j av a2 s .c o m*/ FileUtils.forceMkdir(folder); } catch (IOException e) { log.error("Failed to create directory: {}", folder.getAbsolutePath()); e.printStackTrace(); } } EncogDirectoryPersistence.saveObject(new File("./models/model" + this.trainerID + ".svm"), svm); }
From source file:cec.easyshop.storefront.filters.AbstractAddOnFilterTest.java
protected void createResourceWithContent(final File rootDir, final String relativePath, final String fileName, final String content) throws IOException { final File dir = new File(rootDir, relativePath); FileUtils.forceMkdir(dir); FileUtils.write(new File(dir, fileName), content); }
From source file:com.planet57.gshell.internal.FileSystemAccessImpl.java
@Override public void mkdir(final File dir) throws IOException { checkNotNull(dir);/*from w ww . j a v a 2 s .c o m*/ log.debug("Create directory: {}", dir); FileUtils.forceMkdir(dir); }
From source file:hd3gtv.mydmam.useraction.fileoperation.UAFileOperationTrash.java
public void process(JobProgression progression, UserProfile userprofile, UAConfigurator user_configuration, HashMap<String, SourcePathIndexerElement> source_elements) throws Exception { String user_base_directory_name = userprofile.getBaseFileName_BasedOnEMail(); if (trash_directory_name == null) { trash_directory_name = "Trash"; }//from www.jav a 2 s . com Log2Dump dump = new Log2Dump(); dump.add("user", userprofile.key); dump.add("trash_directory_name", trash_directory_name); dump.add("user_base_directory_name", user_base_directory_name); dump.add("source_elements", source_elements.values()); Log2.log.debug("Prepare trash", dump); progression.update("Prepare trashs directories"); File current_user_trash_dir; HashMap<String, File> trashs_dirs = new HashMap<String, File>(); for (Map.Entry<String, SourcePathIndexerElement> entry : source_elements.entrySet()) { String storagename = entry.getValue().storagename; if (trashs_dirs.containsKey(storagename)) { continue; } File storage_dir = Explorer .getLocalBridgedElement(SourcePathIndexerElement.prepareStorageElement(storagename)); current_user_trash_dir = new File(storage_dir.getPath() + File.separator + trash_directory_name + File.separator + user_base_directory_name); if (current_user_trash_dir.exists() == false) { FileUtils.forceMkdir(current_user_trash_dir); } else { CopyMove.checkExistsCanRead(current_user_trash_dir); CopyMove.checkIsWritable(current_user_trash_dir); CopyMove.checkIsDirectory(current_user_trash_dir); } trashs_dirs.put(storagename, current_user_trash_dir); if (stop) { return; } } progression.update("Move item(s) to trash(s) directorie(s)"); progression.updateStep(1, source_elements.size()); Date now = new Date(); for (Map.Entry<String, SourcePathIndexerElement> entry : source_elements.entrySet()) { progression.incrStep(); File current_element = Explorer.getLocalBridgedElement(entry.getValue()); CopyMove.checkExistsCanRead(current_element); CopyMove.checkIsWritable(current_element); current_user_trash_dir = trashs_dirs.get(entry.getValue().storagename); File f_destination = new File(current_user_trash_dir.getPath() + File.separator + simpledateformat.format(now) + "_" + current_element.getName()); if (current_element.isDirectory()) { FileUtils.moveDirectory(current_element, f_destination); } else { FileUtils.moveFile(current_element, f_destination); } if (stop) { return; } ContainerOperations.copyMoveMetadatas(entry.getValue(), entry.getValue().storagename, "/" + trash_directory_name + "/" + user_base_directory_name, false, this); ElasticsearchBulkOperation bulk = Elasticsearch.prepareBulk(); explorer.deleteStoragePath(bulk, Arrays.asList(entry.getValue())); bulk.terminateBulk(); if (stop) { return; } } ElasticsearchBulkOperation bulk = Elasticsearch.prepareBulk(); ArrayList<SourcePathIndexerElement> spie_trashs_dirs = new ArrayList<SourcePathIndexerElement>(); for (String storage_name : trashs_dirs.keySet()) { SourcePathIndexerElement root_trash_directory = SourcePathIndexerElement .prepareStorageElement(storage_name); root_trash_directory.parentpath = root_trash_directory.prepare_key(); root_trash_directory.directory = true; root_trash_directory.currentpath = "/" + trash_directory_name; spie_trashs_dirs.add(root_trash_directory); } explorer.refreshStoragePath(bulk, spie_trashs_dirs, false); bulk.terminateBulk(); }
From source file:co.turnus.analysis.profiler.SerialDynamicProfiler.java
public void setConfiguration(Configuration configuration) { super.setConfiguration(configuration); actorDataMap = new HashMap<Actor, ActorDataBox>(); for (Actor actor : network.getActors()) { actorDataMap.put(actor, new ActorDataBox(actor)); }//from ww w . jav a 2 s . co m fifoDataMap = new HashMap<Fifo, FifoDataBox>(); int size = getOption(FIFO_DEFAULT);// FIXME add mapping file for (Fifo fifo : network.getFifos()) { fifoDataMap.put(fifo, new FifoDataBox(fifo, size)); } exportTrace = getOption(CREATE_TRACE_PROJECT, false); exportProfiling = exportTrace || getOption(EXPORT_PROFILING, false); exportGantt = getOption(EXPORT_GANTT, false); if (exportProfiling || exportGantt) { File outDir = new File(getOption(OUTPUT_PATH, "")); try { FileUtils.forceMkdir(outDir); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (exportTrace) { // create the trace project String pojo = getOption(TRACE_PROJECT_NAME); new TraceProject(pojo, network.getName(), outDir).save(); // create the file name according to the options and launch the // trace file writer boolean compress = getOption(TRACE_COMPRESS); String ext = compress ? TurnusExtension.TRACE_COMPRESSED : TurnusExtension.TRACE; File traceFile = new File(outDir, network.getName() + "." + ext); traceWriter = new TraceWriter(traceFile); traceWriter.start(); } if (exportGantt) { ganttBuilder = new GanttChartBuilder(network, getOption(SIMULATOR_NAME, "")); ganttBuilder.setConfiguration(configuration); } } }
From source file:com.sonar.it.jenkins.orchestrator.container.JenkinsDownloader.java
private File downloadUrl(String url, File toFile) { try {// www.ja v a2s . com FileUtils.forceMkdir(toFile.getParentFile()); HttpURLConnection conn; URL u = new URL(url); LOG.info("Download: " + u); // gets redirected multiple times, including from https -> http, so not done by Java while (true) { conn = (HttpURLConnection) u.openConnection(); conn.connect(); if (conn.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM || conn.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP) { String newLocationHeader = conn.getHeaderField("Location"); LOG.info("Redirect: " + newLocationHeader); conn.disconnect(); u = new URL(newLocationHeader); continue; } break; } InputStream is = conn.getInputStream(); ByteStreams.copy(is, Files.asByteSink(toFile).openBufferedStream()); LOG.info("Downloaded to: " + toFile); return toFile; } catch (Exception e) { throw new IllegalStateException(e); } }
From source file:com.thoughtworks.go.plugin.infra.monitor.DefaultPluginJarLocationMonitor.java
public void validateBundledPluginDirectory() { if (bundledPluginDirectory.exists()) { return;/* w w w . ja v a2 s .co m*/ } try { LOGGER.debug("Force creating the plugins jar directory as it does not exist {}", bundledPluginDirectory.getAbsolutePath()); FileUtils.forceMkdir(bundledPluginDirectory); } catch (IOException e) { String message = "Failed to create plugins folder in location " + bundledPluginDirectory.getAbsolutePath(); LOGGER.warn(message, e); throw new RuntimeException(message, e); } }