List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:io.druid.segment.loading.LocalDataSegmentPusher.java
@Override public DataSegment push(File dataSegmentFile, DataSegment segment) throws IOException { final String storageDir = this.getStorageDir(segment); final File baseStorageDir = config.getStorageDirectory(); final File outDir = new File(baseStorageDir, storageDir); log.info("Copying segment[%s] to local filesystem at location[%s]", segment.getIdentifier(), outDir.toString());/*from w ww. jav a 2 s . c o m*/ if (dataSegmentFile.equals(outDir)) { long size = 0; for (File file : dataSegmentFile.listFiles()) { size += file.length(); } return createDescriptorFile(segment.withLoadSpec(makeLoadSpec(outDir.toURI())).withSize(size) .withBinaryVersion(SegmentUtils.getVersionFromDir(dataSegmentFile)), outDir); } final File tmpOutDir = new File(baseStorageDir, intermediateDirFor(storageDir)); log.info("Creating intermediate directory[%s] for segment[%s]", tmpOutDir.toString(), segment.getIdentifier()); final long size = compressSegment(dataSegmentFile, tmpOutDir); final DataSegment dataSegment = createDescriptorFile( segment.withLoadSpec(makeLoadSpec(new File(outDir, "index.zip").toURI())).withSize(size) .withBinaryVersion(SegmentUtils.getVersionFromDir(dataSegmentFile)), tmpOutDir); // moving the temporary directory to the final destination, once success the potentially concurrent push operations // will be failed and will read the descriptor.json created by current push operation directly FileUtils.forceMkdir(outDir.getParentFile()); try { Files.move(tmpOutDir.toPath(), outDir.toPath()); } catch (FileAlreadyExistsException e) { log.warn("Push destination directory[%s] exists, ignore this message if replication is configured.", outDir); FileUtils.deleteDirectory(tmpOutDir); return jsonMapper.readValue(new File(outDir, "descriptor.json"), DataSegment.class); } return dataSegment; }
From source file:com.bluexml.side.forms.generator.alfresco.chiba.FormGenerator.java
@Override public void initialize(Map<String, String> generationParameters_, Map<String, Boolean> generatorOptions_, Map<String, String> configurationParameters_, DependencesManager dm, ComponentMonitor monitor) throws Exception { super.initialize(generationParameters_, generatorOptions_, configurationParameters_, dm, monitor); this.monitor = monitor; successfulInit = false;//from w ww . ja va 2 s . c o m setTEMP_FOLDER("generator_" + getClass().getName() + File.separator + defaultModelID); File webappFolder = new File(getTemporarySystemFile(), "webapps" + File.separator + webappName); xformGenerationFolder = new File(webappFolder.getAbsolutePath() + File.separator + "forms"); String classesPathname = webappFolder.getAbsolutePath() + File.separator + "WEB-INF" + File.separator + "classes"; mappingGenerationFolder = new File(classesPathname); FileUtils.forceMkdir(xformGenerationFolder); FileUtils.forceMkdir(mappingGenerationFolder); String baseDir = xformGenerationFolder.getAbsolutePath(); String resDir = mappingGenerationFolder.getAbsolutePath(); File generateMappingFile = new File(resDir + File.separator + "mapping.xml"); File generateRedirectFile = new File(resDir + File.separator + "redirect.xml"); File generateCSSFile = new File(resDir + File.separator + "styles.css"); XFormsGenerator xformsGenerator = new XFormsGenerator(); MappingGenerator mappingGenerator = new MappingGenerator(); generators.add(mappingGenerator); generators.add(xformsGenerator); xformsGenerator.setOutputFolder(baseDir); mappingGenerator.setOutputMappingFile(generateMappingFile.getAbsolutePath()); mappingGenerator.setOutputCSSFile(generateCSSFile.getAbsolutePath()); mappingGenerator.setOutputRedirectFile(generateRedirectFile.getAbsolutePath()); // deal with messages.properties file String messagesFilePath = generationParameters .get("com.bluexml.side.Form.generator.xforms.chiba.messagesFilePath"); if (StringUtils.trimToNull(messagesFilePath) != null) { File file = new File(messagesFilePath); if (file.exists()) { setMessagesFilePath(messagesFilePath); } else { monitor.addWarningText("The specified messages file does not exist. Will generate defaults."); messagesFilePath = null; } } if (StringUtils.trimToNull(messagesFilePath) == null) { String filePath = classesPathname + File.separator + "messages.properties"; if (DefaultMessages.generateMessagesFile(filePath)) { setMessagesFilePath(filePath); } else { monitor.addWarningText("Could not generate and set the messages file."); } } // generate the forms.properties file String filePath = resDir + File.separator + "forms.properties"; if (DefaultMessages.generateFormsFile(filePath, generationParameters) == false) { monitor.addWarningText("Could not generate and set the 'forms.properties' file."); } // deal with the webapp address (protocol, host, port, context) webappContext = generationParameters.get(COM_BLUEXML_SIDE_FORM_GENERATOR_XFORMS_CHIBA_WEBAPP_CONTEXT); if (StringUtils.trimToNull(webappContext) != null) { // we check that the context is not 'forms' int pos = webappContext.lastIndexOf('/'); int len = webappContext.length(); // if there's a trailing "/", remove it if (pos == (len - 1)) { webappContext = webappContext.substring(0, len - 1); } len = webappContext.length(); pos = webappContext.lastIndexOf('/'); String context = webappContext.substring(pos + 1, len); if (context.equals("forms")) { throw new Exception("The context of your webapp SHOULD NOT be 'forms'!"); } } successfulInit = true; }
From source file:com.dianping.phoenix.dev.core.tools.wms.AgentWorkspaceServiceImpl.java
@Override protected void generateContainer(WorkspaceContext context, OutputStream out) throws Exception { checkoutSource(context, out);//from www . j a v a 2 s. c o m File warBase = new File(context.getBaseDir(), WorkspaceConstants.PHOENIX_CONTAINER_FOLDER); File webInfFolder = new File(warBase, "WEB-INF"); File phoenixServerFolder = new File(webInfFolder, "classes/com/dianping/phoenix/container/"); FileUtils.forceMkdir(webInfFolder); FileUtils.forceMkdir(phoenixServerFolder); String libZipName = "lib.zip"; copyFile(libZipName, webInfFolder); ZipUtil.unpack(new File(webInfFolder, libZipName), webInfFolder); FileUtils.deleteQuietly(new File(webInfFolder, libZipName)); ContainerWebXMLGenerator containerWebXMLGenerator = new ContainerWebXMLGenerator(); containerWebXMLGenerator.generate(new File(webInfFolder, "web.xml"), null); String serverClassFileName = "AgentPhoenixServer.classfile"; copyFile(serverClassFileName, phoenixServerFolder); FileUtils.moveFile(new File(phoenixServerFolder, serverClassFileName), new File(phoenixServerFolder, "PhoenixServer.class")); }
From source file:eu.planets_project.services.utils.ZipUtilsTest.java
/** * Test method for {@link eu.planets_project.services.utils.ZipUtils#createZipAndCheck(java.io.File, java.io.File, java.lang.String, boolean)}. * @throws IOException //from w ww . j a v a 2 s . c o m */ @Test public void testCreateZipAndCheckAndCheckAndUnzip() throws IOException { int inputFileCount = ZipUtils.listAllFilesAndFolders(TEST_FILE_FOLDER, new ArrayList<File>()).size(); ZipResult zip = ZipUtils.createZipAndCheck(TEST_FILE_FOLDER, outputFolder, "zipUtilsTestCheck.zip", true); System.out.println("[Checksum]: Algorith=" + zip.getChecksum().getAlgorithm() + " | checksum=" + zip.getChecksum().getValue()); System.out.println("Zip created. Please find it here: " + zip.getZipFile().getAbsolutePath()); String folderName = zip.getZipFile().getName().substring(0, zip.getZipFile().getName().lastIndexOf(".")); File extract = new File(outputFolder, folderName); FileUtils.forceMkdir(extract); List<File> extracted = ZipUtils.checkAndUnzipTo(zip.getZipFile(), extractResultOut, zip.getChecksum()); System.out.println("Extracted files:" + System.getProperty("line.separator")); for (File file : extracted) { System.out.println(file.getAbsolutePath()); } System.out.println("input file-count: " + inputFileCount); System.out.println("output file-count: " + extracted.size()); }
From source file:algorithm.BagItPackaging.java
@Override public File encapsulate(File carrier, List<File> payload) throws IOException { String carrierName = carrier.getName(); String bagDirectoryName = OUTPUT_DIRECTORY + carrierName + "_BAG"; FileUtils.forceMkdir(new File(bagDirectoryName)); File bagDirectory = new File(bagDirectoryName); new File(bagDirectory, "manifest-md5.txt");// manifest new File(bagDirectory, "tagmanifest-md5.txt"); // metadata manifest new File(bagDirectory, "data"); // carrier directory Filler filler = new Filler(bagDirectory); // add the DO file: InputStream inputStream = new FileInputStream("" + carrier); filler = filler.payload("" + carrier.getName(), inputStream); // add all metadata files: for (File payloadFile : payload) { InputStream inputStream2 = new FileInputStream("" + payloadFile); filler = filler.tag("" + payloadFile.getName(), inputStream2); }//from w w w.j a va2 s. c o m return filler.toPackage(); }
From source file:com.galenframework.reports.json.JsonReportBuilder.java
private void makeSureFolderExists(String reportPath) throws IOException { FileUtils.forceMkdir(new File(reportPath)); }
From source file:com.temenos.interaction.loader.classloader.CachingParentLastURLClassloaderFactory.java
protected synchronized URLClassLoader createClassLoader(Object currentState, FileEvent<File> param) { try {/* ww w. ja v a 2 s .com*/ LOGGER.debug( "Classloader requested from CachingParentLastURLClassloaderFactory, based on FileEvent reflecting change in {}", param.getResource().getAbsolutePath()); Set<URL> urls = new HashSet<URL>(); File newTempDir = new File(FileUtils.getTempDirectory(), currentState.toString()); FileUtils.forceMkdir(newTempDir); Collection<File> files = FileUtils.listFiles(param.getResource(), new String[] { "jar" }, true); for (File f : files) { try { LOGGER.trace("Adding {} to list of URLs to create classloader from", f.toURI().toURL()); FileUtils.copyFileToDirectory(f, newTempDir); urls.add(new File(newTempDir, f.getName()).toURI().toURL()); } catch (MalformedURLException ex) { // should not happen, we do have the file there // but if, what can we do - just log it LOGGER.warn("Trying to intilialize classloader based on URL failed!", ex); } } lastClassloaderTempDir = newTempDir; URLClassLoader classloader = new ParentLastURLClassloader(urls.toArray(new URL[] {}), Thread.currentThread().getContextClassLoader()); return classloader; } catch (IOException ex) { throw new RuntimeException("Unexpected error trying to create new classloader.", ex); } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.miRnaSeqData.MiRnaSeqLoadAnnotationListener.java
@Override protected void setJobMetadata(Job job) throws Exception { job.getJobMeta().setParameterValue("DATA_LOCATION", dataType.getPath().getAbsolutePath()); File sort = new File(sortName); if (!sort.exists()) { FileUtils.forceMkdir(sort); }// ww w. j av a 2 s . c om job.getJobMeta().setParameterValue("SORT_DIR", sort.getAbsolutePath()); job.getJobMeta().setParameterValue("MIRNA_TYPE", "MIRNA_SEQ"); job.getJobMeta().setParameterValue("SAMPLE_MAP_FILENAME", ((MiRnaSeqData) dataType).getMappingFile().getName()); job.getJobMeta().setParameterValue("GPL_ID", platformId); job.getJobMeta().setParameterValue("ANNOTATION_TITLE", annotationTitle); job.getJobMeta().setParameterValue("LOAD_TYPE", "I"); if (((HDDData) dataType).isIncremental()) job.getJobMeta().setParameterValue("INC_LOAD", "Y"); else job.getJobMeta().setParameterValue("INC_LOAD", "Y"); job.getJobMeta().setParameterValue("INC_LOAD", "N"); job.getJobMeta().setParameterValue("TM_CZ_DB_SERVER", PreferencesHandler.getDbServer()); job.getJobMeta().setParameterValue("TM_CZ_DB_NAME", PreferencesHandler.getDbName()); job.getJobMeta().setParameterValue("TM_CZ_DB_PORT", PreferencesHandler.getDbPort()); job.getJobMeta().setParameterValue("TM_CZ_DB_USER", PreferencesHandler.getTm_czUser()); job.getJobMeta().setParameterValue("TM_CZ_DB_PWD", PreferencesHandler.getTm_czPwd()); job.getJobMeta().setParameterValue("TM_LZ_DB_SERVER", PreferencesHandler.getDbServer()); job.getJobMeta().setParameterValue("TM_LZ_DB_NAME", PreferencesHandler.getDbName()); job.getJobMeta().setParameterValue("TM_LZ_DB_PORT", PreferencesHandler.getDbPort()); job.getJobMeta().setParameterValue("TM_LZ_DB_USER", PreferencesHandler.getTm_lzUser()); job.getJobMeta().setParameterValue("TM_LZ_DB_PWD", PreferencesHandler.getTm_lzPwd()); job.getJobMeta().setParameterValue("DEAPP_DB_SERVER", PreferencesHandler.getDbServer()); job.getJobMeta().setParameterValue("DEAPP_DB_NAME", PreferencesHandler.getDbName()); job.getJobMeta().setParameterValue("DEAPP_DB_PORT", PreferencesHandler.getDbPort()); job.getJobMeta().setParameterValue("DEAPP_DB_USER", PreferencesHandler.getDeappUser()); job.getJobMeta().setParameterValue("DEAPP_DB_PWD", PreferencesHandler.getDeappPwd()); }
From source file:edu.ur.ir.ir_export.service.DefaultCollectionExportService.java
/** * Export the specified institutional collection. * /*from w w w.j a v a2 s . co m*/ * @param collection - collection to export * @param includeChildren - if true children should be exported * @param zipFileDestination - zip file destination to store the collection information * @throws IOException */ public void export(InstitutionalCollection collection, boolean includeChildren, File zipFileDestination) throws IOException { // create the path if it doesn't exist String path = FilenameUtils.getPath(zipFileDestination.getCanonicalPath()); if (!path.equals("")) { File pathOnly = new File(FilenameUtils.getFullPath(zipFileDestination.getCanonicalPath())); FileUtils.forceMkdir(pathOnly); } List<InstitutionalCollection> collections = new LinkedList<InstitutionalCollection>(); collections.add(collection); File collectionXmlFile = temporaryFileCreator.createTemporaryFile(extension); Set<FileInfo> allPictures = createXmlFile(collectionXmlFile, collections, includeChildren); FileOutputStream out = new FileOutputStream(zipFileDestination); ArchiveOutputStream os = null; try { os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out); os.putArchiveEntry(new ZipArchiveEntry("collection.xml")); FileInputStream fis = null; try { log.debug("adding xml file"); fis = new FileInputStream(collectionXmlFile); IOUtils.copy(fis, os); } finally { if (fis != null) { fis.close(); fis = null; } } log.debug("adding pictures size " + allPictures.size()); for (FileInfo fileInfo : allPictures) { File f = new File(fileInfo.getFullPath()); String name = FilenameUtils.getName(fileInfo.getFullPath()); name = name + '.' + fileInfo.getExtension(); log.debug(" adding name " + name); os.putArchiveEntry(new ZipArchiveEntry(name)); try { log.debug("adding input stream"); fis = new FileInputStream(f); IOUtils.copy(fis, os); } finally { if (fis != null) { fis.close(); fis = null; } } } os.closeArchiveEntry(); out.flush(); } catch (ArchiveException e) { throw new IOException(e); } finally { if (os != null) { os.close(); os = null; } } FileUtils.deleteQuietly(collectionXmlFile); }
From source file:functionaltests.workflow.TestJobLegacySchemas.java
private void prepareDataspaceFolder() throws IOException { File ds = new File(PAResourceManagerProperties.RM_HOME.getValueAsString(), "/scheduler/scheduler-server/build/JobLegacySchemas_dataspace"); if (ds.exists()) { File[] filesToDelete = ds.listFiles(new FilenameFilter() { @Override/* w w w . ja v a2 s. c om*/ public boolean accept(File dir, String name) { return name.startsWith("myfileout") || name.endsWith(".log"); } }); for (File f : filesToDelete) { FileUtils.forceDelete(f); } } else { FileUtils.forceMkdir(ds); } }