List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:edu.ur.ir.repository.service.test.helper.RepositoryBasedTestHelper.java
/** * Creates a repository ready for use in testing. * //w w w .j a va2s. c o m * @return the created repository. * @throws LocationAlreadyExistsException * @throws IOException */ public Repository createTestRepositoryDefaultFileServer(Properties properties) throws LocationAlreadyExistsException { String fileServerName = "localFileServer"; String fileDatabaseDisplayName = "displayName"; String fileDatabaseUniqueName = "file_database"; String repoName = "my_repository"; // location for the default file database String fileDatabasePath = properties.getProperty("a_repo_path"); // location to store person name index String nameIndexFolder = properties.getProperty("name_index_folder"); // location to store item index folder String itemIndexFolder = properties.getProperty("item_index_folder"); // location to store user index folder String userIndexFolder = properties.getProperty("user_index_folder"); // location to store user personal workspace index folders String userWorkspaceIndexFolder = properties.getProperty("user_workspace_index_folder"); // location to store institutional collection index folders String institutionalCollectionIndexFolder = properties.getProperty("institutional_collection_index_folder"); // location to store institutional collection index folders String userGroupIndexFolder = properties.getProperty("user_group_index_folder"); // location to store group workspace index String groupWorkspaceIndexFolder = properties.getProperty("group_workspace_index_folder"); // create each of the folders File f = new File(nameIndexFolder); if (!f.exists()) { try { FileUtils.forceMkdir(f); } catch (IOException e) { throw new IllegalStateException(e); } } f = new File(itemIndexFolder); if (!f.exists()) { try { FileUtils.forceMkdir(f); } catch (IOException e) { throw new IllegalStateException(e); } } f = new File(userIndexFolder); if (!f.exists()) { try { FileUtils.forceMkdir(f); } catch (IOException e) { throw new IllegalStateException(e); } } f = new File(userWorkspaceIndexFolder); if (!f.exists()) { try { FileUtils.forceMkdir(f); } catch (IOException e) { throw new IllegalStateException(e); } } f = new File(institutionalCollectionIndexFolder); if (!f.exists()) { try { FileUtils.forceMkdir(f); } catch (IOException e) { throw new IllegalStateException(e); } } f = new File(userGroupIndexFolder); if (!f.exists()) { try { FileUtils.forceMkdir(f); } catch (IOException e) { throw new IllegalStateException(e); } } f = new File(groupWorkspaceIndexFolder); if (!f.exists()) { try { FileUtils.forceMkdir(f); } catch (IOException e) { throw new IllegalStateException(e); } } String defaultFolderDispalyName = "default_folder"; // create the file server fileServer = fileServerService.createFileServer(fileServerName); // create the file database DefaultFileDatabaseInfo fileDatabaseInfo = new DefaultFileDatabaseInfo(fileServer.getId(), fileDatabaseDisplayName, fileDatabaseUniqueName, fileDatabasePath, defaultFolderDispalyName, "uniqueFolderName"); DefaultFileDatabase fileDatabase = fileServerService.createFileDatabase(fileDatabaseInfo); repository = repositoryService.createRepository(repoName, fileDatabase); // Creating the name index folder repository.setNameIndexFolder(nameIndexFolder); // create the institutional item index folder repository.setInstitutionalItemIndexFolder(itemIndexFolder); //create the index folder for user information repository.setUserIndexFolder(userIndexFolder); //set the user workspace index folders location repository.setUserWorkspaceIndexFolder(userWorkspaceIndexFolder); //set the collection index folders location repository.setInstitutionalCollectionIndexFolder(institutionalCollectionIndexFolder); //set the user group index folders location repository.setUserGroupIndexFolder(userGroupIndexFolder); // set the group workspace index folder repository.setGroupWorkspaceIndexFolder(groupWorkspaceIndexFolder); repositoryService.saveRepository(repository); return repository; }
From source file:com.norconex.collector.core.crawler.AbstractCrawler.java
/** * Constructor.//ww w .java 2 s . c o m * @param config crawler configuration */ public AbstractCrawler(ICrawlerConfig config) { this.config = config; try { FileUtils.forceMkdir(config.getWorkDir()); } catch (IOException e) { throw new CollectorException("Cannot create working directory: " + config.getWorkDir(), e); } }
From source file:de.egore911.versioning.deployer.Main.java
private static void perform(String arg, CommandLine line) throws IOException { URL url;//from ww w. j a v a 2 s. com try { url = new URL(arg); } catch (MalformedURLException e) { LOG.error("Invalid URI: {}", e.getMessage(), e); System.exit(1); return; } HttpURLConnection connection; try { connection = (HttpURLConnection) url.openConnection(); int response = connection.getResponseCode(); if (response != HttpURLConnection.HTTP_OK) { LOG.error("Could not download {}", url); connection.disconnect(); System.exit(1); return; } } catch (ConnectException e) { LOG.error("Error during download from URI {}: {}", url, e.getMessage()); System.exit(1); return; } XmlHolder xmlHolder = XmlHolder.getInstance(); DocumentBuilder documentBuilder = xmlHolder.documentBuilder; XPath xPath = xmlHolder.xPath; try { XPathExpression serverNameXpath = xPath.compile("/server/name/text()"); XPathExpression serverTargetdirXpath = xPath.compile("/server/targetdir/text()"); XPathExpression serverDeploymentsDeploymentXpath = xPath.compile("/server/deployments/deployment"); Document doc = documentBuilder.parse(connection.getInputStream()); connection.disconnect(); String serverName = (String) serverNameXpath.evaluate(doc, XPathConstants.STRING); LOG.info("Deploying {}", serverName); boolean shouldPerformCopy = !line.hasOption('r'); PerformCopy performCopy = new PerformCopy(xPath); boolean shouldPerformExtraction = !line.hasOption('r'); PerformExtraction performExtraction = new PerformExtraction(xPath); boolean shouldPerformCheckout = !line.hasOption('r'); PerformCheckout performCheckout = new PerformCheckout(xPath); boolean shouldPerformReplacement = true; PerformReplacement performReplacement = new PerformReplacement(xPath); String targetdir = (String) serverTargetdirXpath.evaluate(doc, XPathConstants.STRING); FileUtils.forceMkdir(new File(targetdir)); NodeList serverDeploymentsDeploymentNodes = (NodeList) serverDeploymentsDeploymentXpath.evaluate(doc, XPathConstants.NODESET); int max = serverDeploymentsDeploymentNodes.getLength(); for (int i = 0; i < serverDeploymentsDeploymentNodes.getLength(); i++) { Node serverDeploymentsDeploymentNode = serverDeploymentsDeploymentNodes.item(i); // Copy if (shouldPerformCopy) { performCopy.perform(serverDeploymentsDeploymentNode); } // Extraction if (shouldPerformExtraction) { performExtraction.perform(serverDeploymentsDeploymentNode); } // Checkout if (shouldPerformCheckout) { performCheckout.perform(serverDeploymentsDeploymentNode); } // Replacement if (shouldPerformReplacement) { performReplacement.perform(serverDeploymentsDeploymentNode); } logPercent(i + 1, max); } // validate that "${versioning:" is not present Collection<File> files = FileUtils.listFiles(new File(targetdir), TrueFileFilter.TRUE, TrueFileFilter.INSTANCE); for (File file : files) { String content; try { content = FileUtils.readFileToString(file); } catch (IOException e) { continue; } if (content.contains("${versioning:")) { LOG.error("{} contains placeholders even after applying the replacements", file.getAbsolutePath()); } } LOG.info("Done deploying {}", serverName); } catch (SAXException | IOException | XPathExpressionException e) { LOG.error("Error performing deployment: {}", e.getMessage(), e); } }
From source file:edu.uci.ics.pregelix.example.asterixdb.ConnectorTest.java
private static void cleanupStores() throws IOException { FileUtils.forceMkdir(new File("teststore")); FileUtils.forceMkdir(new File("build")); FileUtils.forceDelete(new File("teststore")); FileUtils.forceDelete(new File("build")); }
From source file:de.egore911.versioning.deployer.performer.PerformCopy.java
private boolean copy(String uri, String target, String targetFilename) { URL url;/* w w w . ja v a 2s . com*/ try { url = new URL(uri); } catch (MalformedURLException e) { LOG.error("Invalid URI: {}", e.getMessage(), e); return false; } try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); int response = connection.getResponseCode(); int lastSlash = uri.lastIndexOf('/'); if (lastSlash < 0) { LOG.error("Invalid URI: {}", uri); return false; } int lastDot = uri.lastIndexOf('.'); if (lastDot < 0) { LOG.error("Invalid URI: {}", uri); return false; } String filename; if (StringUtils.isEmpty(targetFilename)) { filename = uri.substring(lastSlash + 1); } else { filename = targetFilename; } XmlHolder xmlHolder = XmlHolder.getInstance(); XPathExpression finalNameXpath = xmlHolder.xPath.compile("/project/build/finalName/text()"); if (response == HttpURLConnection.HTTP_OK) { String downloadFilename = UrlUtil.concatenateUrlWithSlashes(target, filename); File downloadFile = new File(downloadFilename); FileUtils.forceMkdir(downloadFile.getParentFile()); try (InputStream in = connection.getInputStream(); FileOutputStream out = new FileOutputStream(downloadFilename)) { IOUtils.copy(in, out); } LOG.debug("Downloaded {} to {}", url, downloadFilename); if (StringUtils.isEmpty(targetFilename)) { // Check if finalName if exists in pom.xml String destFile = null; try (ZipFile zipFile = new ZipFile(downloadFilename)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().endsWith("/pom.xml")) { String finalNameInPom; try (InputStream inputStream = zipFile.getInputStream(entry)) { try { MavenXpp3Reader mavenreader = new MavenXpp3Reader(); Model model = mavenreader.read(inputStream); finalNameInPom = model.getBuild().getFinalName(); } catch (Exception e) { Document doc = xmlHolder.documentBuilder.parse(inputStream); finalNameInPom = (String) finalNameXpath.evaluate(doc, XPathConstants.STRING); } } if (StringUtils.isNotEmpty(finalNameInPom)) { destFile = UrlUtil.concatenateUrlWithSlashes(target, finalNameInPom + "." + uri.substring(lastDot + 1)); } break; } } } // Move file to finalName if existed in pom.xml if (destFile != null) { try { File dest = new File(destFile); if (dest.exists()) { FileUtils.forceDelete(dest); } FileUtils.moveFile(downloadFile.getAbsoluteFile(), dest.getAbsoluteFile()); LOG.debug("Moved file from {} to {}", downloadFilename, destFile); } catch (IOException e) { LOG.error("Failed to move file to it's final name: {}", e.getMessage(), e); } } } return true; } else { LOG.error("Could not download file: {}", uri); return false; } } catch (SAXException | IOException | XPathExpressionException e) { LOG.error("Could not download file ({}): {}", uri, e.getMessage(), e); return false; } }
From source file:io.druid.segment.loading.LocalDataSegmentPusher.java
private long compressSegment(File dataSegmentFile, File outDir) throws IOException { FileUtils.forceMkdir(outDir); File outFile = new File(outDir, "index.zip"); log.info("Compressing files from[%s] to [%s]", dataSegmentFile, outFile); return CompressionUtils.zip(dataSegmentFile, outFile); }
From source file:aurelienribon.gdxsetupui.ProjectSetup.java
/** * The raw structure of all projects is contained in a zip file. This * method inflates this file in a temporary folder. * @throws IOException// w w w . j a va2 s . com */ public void inflateProjects() throws IOException { FileUtils.forceMkdir(tmpDst); FileUtils.cleanDirectory(tmpDst); InputStream is = Res.getStream("projects.zip"); ZipInputStream zis = new ZipInputStream(is); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { File file = new File(tmpDst, entry.getName()); if (entry.isDirectory()) { FileUtils.forceMkdir(file); } else { OutputStream os = new FileOutputStream(file); IOUtils.copy(zis, os); os.close(); } } zis.close(); }
From source file:com.voodoowarez.alclassicist.CtDumpMojo.java
protected void writeClass(final CtClass klass) throws MojoExecutionException { final String klassName = klass.getName(), pathedName = this.outputDirectory + klassName.replace(".", "/") + this.ctSuffix; final File file = new File(pathedName); try {/*w w w . java 2s . c om*/ FileUtils.forceMkdir(file.getParentFile()); } catch (IOException e) { throw new MojoExecutionException("Couldn't create directory " + file.getParent() + " for " + klassName, e); } try { this.objectMapper.writeValue(file, klass); } catch (Exception e) { throw new MojoExecutionException("Couldn't output CtClass " + klassName, e); } }
From source file:ch.entwine.weblounge.maven.MyGengoI18nImport.java
private void importLanguageFile(String name, InputStream file) { String lang = name.substring(0, name.indexOf("/")); String filename = name.substring(name.indexOf("/") + 1); String path;/* w w w . j av a 2 s . c om*/ if (filename.startsWith(siteId)) { log.info("Importing i18n file " + name); if ((siteId + "_site.xml").equals(filename)) { if (StringUtils.equalsIgnoreCase(lang, defaultLang)) path = "/i18n/message.xml"; else path = "/i18n/message_" + lang + ".xml"; } else { String filenameNoSite = filename.substring(filename.indexOf("_") + 1); String module = filenameNoSite.substring(filenameNoSite.indexOf("_") + 1, filenameNoSite.indexOf(".")); if (StringUtils.equalsIgnoreCase(lang, defaultLang)) path = "/modules/" + module + "/i18n/message.xml"; else path = "/modules/" + module + "/i18n/message_" + lang + ".xml"; } File dest = new File(siteRoot, path); try { FileUtils.forceMkdir(dest.getParentFile()); if (!dest.exists()) dest.createNewFile(); IOUtils.copy(file, new FileOutputStream(dest)); } catch (IOException e) { log.error("Error importing i18n file " + name); return; } } }
From source file:com.linkedin.pinot.controller.api.restlet.resources.PinotSegmentUploadRestletResource.java
public PinotSegmentUploadRestletResource() throws IOException { baseDataDir = new File(_controllerConf.getDataDir()); if (!baseDataDir.exists()) { FileUtils.forceMkdir(baseDataDir); }//from w w w .j a va 2 s.c o m tempDir = new File(baseDataDir, "fileUploadTemp"); if (!tempDir.exists()) { FileUtils.forceMkdir(tempDir); } tempUntarredPath = new File(tempDir, "untarred"); if (!tempUntarredPath.exists()) { tempUntarredPath.mkdirs(); } vip = _controllerConf.generateVipUrl(); segmentCompletionManager = SegmentCompletionManager.getInstance(); LOGGER.info("controller download url base is : " + vip); }