List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:com.thoughtworks.go.agent.AgentPluginsInitializerIntegrationTest.java
private File setupUnzippedPluginsDirectoryStructure() throws IOException { File dir = temporaryFolder.newFolder("unzipped-plugins"); FileUtils.forceMkdir(new File(dir, "bundled")); FileUtils.forceMkdir(new File(dir, "external")); return dir;//from w ww .j av a 2 s .co m }
From source file:com.ipcglobal.fredimport.process.ProcessReadmeSeriesId.java
/** * Run create table tsvs./*from ww w. ja va2 s . c om*/ * * @param fredItems the fred items * @throws Exception the exception */ private void runCreateTableTsvs(List<FredItem> fredItems) throws Exception { File filePathTableTsvFiles = new File(outputPathTableTsvFiles); FileUtils.forceMkdir(filePathTableTsvFiles); int numThreads = 2 * Runtime.getRuntime().availableProcessors(); List<CreateTableTsvs> createTableTsvsThreads = new ArrayList<CreateTableTsvs>(numThreads); List<List<FredItem>> listFredItems = new ArrayList<List<FredItem>>(numThreads); for (int i = 0; i < numThreads; i++) { List<FredItem> newFredItems = new ArrayList<FredItem>(); listFredItems.add(newFredItems); createTableTsvsThreads.add(new CreateTableTsvs(i, newFredItems)); } int threadNum = 0; for (int i = 0; i < fredItems.size(); i++) { listFredItems.get(threadNum).add(fredItems.get(i)); threadNum++; if (threadNum == numThreads) threadNum = 0; } for (CreateTableTsvs createTableTsvs : createTableTsvsThreads) createTableTsvs.start(); for (CreateTableTsvs createTableTsvs : createTableTsvsThreads) createTableTsvs.join(); for (FredItem fredItem : fredItems) { Integer hashCategories = fredItem.hashCodeCategories(); DistinctCategoryItem distinctCategoryItem = distinctCategoryItems.get(hashCategories); if (distinctCategoryItem != null) distinctCategoryItem.updateDistinctFields(fredItem); else { distinctCategoryItem = new DistinctCategoryItem(fredItem); distinctCategoryItems.put(hashCategories, distinctCategoryItem); } } }
From source file:com.dv.util.DataViewerZipUtil.java
/** * * @param zipInput/*from w w w . java 2 s . c om*/ * @param dest * @throws IOException */ private static void doUnzipFile(ZipInputStream zipInput, File dest) throws IOException { if (!dest.exists()) { FileUtils.forceMkdir(dest); } for (ZipEntry entry; (entry = zipInput.getNextEntry()) != null;) { String entryName = entry.getName(); File file = new File(dest, entry.getName()); if (entryName.endsWith(File.separator)) { FileUtils.forceMkdir(file); } else { OutputStream out = FileUtils.openOutputStream(file); try { IOUtils.copy(zipInput, out); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(out); } } zipInput.closeEntry(); } }
From source file:cpcc.ros.sim.osm.CameraTest.java
@BeforeMethod public void setUp() throws Exception { int port = RandomUtils.nextInt(30000, 50000); gs = new WGS84(); tempDir = File.createTempFile("camera", ""); tempDir.delete();/*w ww . j a v a 2s . c om*/ FileUtils.forceMkdir(tempDir); config = mock(Configuration.class); when(config.getCameraHeight()).thenReturn(240); when(config.getCameraWidth()).thenReturn(320); when(config.getTileHeight()).thenReturn(256); when(config.getTileWidth()).thenReturn(256); when(config.getOriginPosition()).thenReturn(null); when(config.getCameraApertureAngle()).thenReturn(2.0); when(config.getTileServerUrl()).thenReturn("http://localhost:" + port + "/%1$d/%2$d/%3$d.png"); when(config.getZoomLevel()).thenReturn(18); when(config.getGeodeticSystem()).thenReturn(gs); when(config.getTileCacheBaseDir()).thenReturn(tempDir.getAbsolutePath()); camera = new Camera(config); testFileHandler = new MyHttpFileHandler(); testFileHandler.getResponses().put("/18/41920/101290.png", new Object[] { "image/png", blackTileFile }); testFileHandler.getResponses().put("/18/41920/101291.png", new Object[] { "image/png", blueTileFile }); testFileHandler.getResponses().put("/18/41920/101292.png", new Object[] { "image/png", cyanTileFile }); testFileHandler.getResponses().put("/18/41920/101293.png", new Object[] { "image/png", greenTileFile }); testFileHandler.getResponses().put("/18/41920/101294.png", new Object[] { "image/png", purpleTileFile }); testFileHandler.getResponses().put("/18/41921/101290.png", new Object[] { "image/png", redTileFile }); testFileHandler.getResponses().put("/18/41921/101291.png", new Object[] { "image/png", whiteTileFile }); testFileHandler.getResponses().put("/18/41921/101292.png", new Object[] { "image/png", blackTileFile }); testFileHandler.getResponses().put("/18/41921/101293.png", new Object[] { "image/png", blueTileFile }); testFileHandler.getResponses().put("/18/41921/101294.png", new Object[] { "image/png", cyanTileFile }); testFileHandler.getResponses().put("/18/41922/101290.png", new Object[] { "image/png", greenTileFile }); testFileHandler.getResponses().put("/18/41922/101291.png", new Object[] { "image/png", purpleTileFile }); testFileHandler.getResponses().put("/18/41922/101292.png", new Object[] { "image/png", redTileFile }); testFileHandler.getResponses().put("/18/41922/101293.png", new Object[] { "image/png", whiteTileFile }); testFileHandler.getResponses().put("/18/41922/101294.png", new Object[] { "image/png", blackTileFile }); testFileHandler.getResponses().put("/18/41923/101290.png", new Object[] { "image/png", blueTileFile }); testFileHandler.getResponses().put("/18/41923/101291.png", new Object[] { "image/png", cyanTileFile }); testFileHandler.getResponses().put("/18/41923/101292.png", new Object[] { "image/png", greenTileFile }); testFileHandler.getResponses().put("/18/41923/101293.png", new Object[] { "image/png", purpleTileFile }); testFileHandler.getResponses().put("/18/41923/101294.png", new Object[] { "image/png", redTileFile }); testFileHandler.getResponses().put("/18/41924/101290.png", new Object[] { "image/png", whiteTileFile }); testFileHandler.getResponses().put("/18/41924/101291.png", new Object[] { "image/png", blackTileFile }); testFileHandler.getResponses().put("/18/41924/101292.png", new Object[] { "image/png", blueTileFile }); testFileHandler.getResponses().put("/18/41924/101293.png", new Object[] { "image/png", cyanTileFile }); testFileHandler.getResponses().put("/18/41924/101294.png", new Object[] { "image/png", greenTileFile }); // whiteTileFile testFileHandler.getResponses().put("/18/41925/101290.png", new Object[] { "image/png", purpleTileFile }); testFileHandler.getResponses().put("/18/41925/101291.png", new Object[] { "image/png", redTileFile }); testFileHandler.getResponses().put("/18/41925/101292.png", new Object[] { "image/png", whiteTileFile }); testFileHandler.getResponses().put("/18/41925/101293.png", new Object[] { "image/png", blackTileFile }); testFileHandler.getResponses().put("/18/41925/101294.png", new Object[] { "image/png", blueTileFile }); testFileHandler.getResponses().put("/18/41926/101290.png", new Object[] { "image/png", cyanTileFile }); testFileHandler.getResponses().put("/18/41926/101291.png", new Object[] { "image/png", greenTileFile }); testFileHandler.getResponses().put("/18/41926/101292.png", new Object[] { "image/png", purpleTileFile }); testFileHandler.getResponses().put("/18/41926/101293.png", new Object[] { "image/png", redTileFile }); testFileHandler.getResponses().put("/18/41926/101294.png", new Object[] { "image/png", whiteTileFile }); HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl()) .build(); UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", testFileHandler); HttpService httpService = new HttpService(httpproc, reqistry); requestListenerThread = new RequestListenerThread(port, httpService); requestListenerThread.setDaemon(false); requestListenerThread.start(); }
From source file:com.github.nukesparrow.htmlunit.DebuggingWebConnection.java
public DebuggingWebConnection(WebConnection wrapped, String dirName) { this(wrapped); final File tmpDir = new File(System.getProperty("java.io.tmpdir")); File reportFolder_ = new File(tmpDir, dirName); try {//from w w w . j ava 2s . c o m if (reportFolder_.exists()) { FileUtils.forceDelete(reportFolder_); } FileUtils.forceMkdir(reportFolder_); } catch (IOException ex) { throw new RuntimeException(ex); } logFile = new File(reportFolder_, "log.html"); }
From source file:dynamicrefactoring.domain.xml.ExportImportUtilities.java
/** * Se encarga del proceso de exportacin de un plan de refactorizaciones * dinmicas.//from w w w. j a v a 2 s . c o m * * @param destination * directorio a donde se quiere exportar el plan. * @throws IOException * IOException. * @throws XMLRefactoringReaderException * XMLRefactoringReaderException. */ public static void exportRefactoringPlan(String destination) throws IOException, XMLRefactoringReaderException { if (new File(destination + "/refactoringPlan").exists()) { //$NON-NLS-1$ FileManager.emptyDirectories(destination + "/refactoringPlan"); //$NON-NLS-1$ FileManager.deleteDirectories(destination + "/refactoringPlan", true); //$NON-NLS-1$ } // Creamos el directorio donde se guardar el plan. FileUtils.forceMkdir(new File(destination + "/refactoringPlan")); //$NON-NLS-1$ // Copiamos el fichero xml que guarda la informacin relativa al plan. FileManager.copyFile(new File(RefactoringConstants.REFACTORING_PLAN_FILE), new File(destination + "/refactoringPlan/" //$NON-NLS-1$ + new File(RefactoringConstants.REFACTORING_PLAN_FILE).getName())); FileManager.copyFile(new File(RefactoringConstants.REFACTORING_PLAN_DTD), new File(destination + "/refactoringPlan/" //$NON-NLS-1$ + new File(RefactoringConstants.REFACTORING_PLAN_DTD).getName())); // Creamos una carpeta donde guardaremos las refactorizaciones. String refactoringDestination = destination + "/refactoringPlan/refactorings"; //$NON-NLS-1$ FileUtils.forceMkdir(new File(refactoringDestination)); // Pasamos a exportar las refactorizaciones necesarias dentro de la // carpeta anterior. ArrayList<String> refactorings = RefactoringPlanReader.readAllRefactoringsFromThePlan(); HashMap<String, String> allRefactorings = DynamicRefactoringLister.getInstance() .getDynamicRefactoringNameList(RefactoringPlugin.getDynamicRefactoringsDir(), true, null); allRefactorings.putAll(DynamicRefactoringLister.getInstance().getDynamicRefactoringNameList( RefactoringPlugin.getNonEditableDynamicRefactoringsDir(), true, null)); for (String next : refactorings) { String key = next + " (" + next + ".xml)"; //$NON-NLS-1$ //$NON-NLS-2$ String definition = allRefactorings.get(key);// ruta del fichero de // definicin de al // refactorizacin exportRefactoring(refactoringDestination, definition, true); } }
From source file:com.qcadoo.model.internal.file.FileServiceImpl.java
private File getFileFromFilename(final String filename) throws IOException { File directory = new File(uploadDirectory, MultiTenantUtil.getCurrentTenantId() + File.separator); try {//www . j a v a 2 s . co m FileUtils.forceMkdir(directory); } catch (IOException e) { LOG.error(e.getMessage(), e); throw e; } return new File(directory, getNormalizedFileName(filename.substring(filename.lastIndexOf(File.separator) + 1))); }
From source file:jp.co.tis.gsp.tools.dba.mojo.GenerateEntity.java
/** * S2JDBC-GEN??Entity??/*ww w . jav a 2 s.c om*/ * Entity??dicon???????? */ @Override protected void executeMojoSpec() throws MojoExecutionException, MojoFailureException { Configuration fmConfig = new Configuration(); fmConfig.setTemplateLoader(new ClassTemplateLoader(Erd.class, "/jp/co/tis/gsp/tools/dba/template/dicon")); Map<String, Object> param = new HashMap<String, Object>(); param.put("driver", driver); param.put("url", url); param.put("user", adminUser); /* NULL?freemarker??InvalidReferenceException???? Mojo?parameter??NULL???????????? */ param.put("password", (adminPassword == null) ? "" : adminPassword); param.put("rootPackage", rootPackage); String[] urlTokens = StringUtils.split(url, ':'); if (urlTokens.length < 3) { throw new MojoExecutionException("Invalid url:" + url); } String databaseProduct = StringUtils.capitalize(urlTokens[1]); if ("Postgresql".equals(databaseProduct)) { databaseProduct = "Postgre"; } else if ("Sqlserver".equals(databaseProduct)) { databaseProduct = "Mssql"; } String dialectClass = this.dialectClassName != null ? dialectClassName : "org.seasar.extension.jdbc.dialect." + databaseProduct + "Dialect"; if (StringUtil.equals(databaseProduct, "Solr")) { dialectClass = "net.unit8.solr.jdbc.extension.s2jdbc.dialect.SolrDialect"; } param.put("databaseProduct", databaseProduct); param.put("dialectClass", dialectClass); try { if (!diconDir.exists()) FileUtils.forceMkdir(diconDir); for (String templateName : templateNames) { Template template = fmConfig.getTemplate(templateName + ".dicon.ftl"); template.process(param, new FileWriter(new File(diconDir, templateName + ".dicon"))); } } catch (IOException e) { throw new MojoExecutionException("Can't generate dicon file.", e); } catch (TemplateException e) { throw new MojoExecutionException("Can't generate dicon file.", e); } executeGenerateEntity(); }
From source file:com.zaba37.easyreader.actions.menuBar.ImageBackgroundLoader.java
private String createWindowsDirecotry(String mainPath) { mainPath = mainPath.substring(0, mainPath.lastIndexOf("/")); mainPath = mainPath + "/TmpEasyReaderImageDirectory"; File file = new File(mainPath); try {//from www .j av a 2 s . c o m if (file.exists()) { FileUtils.forceDelete(file); } FileUtils.forceMkdir(file); Files.setAttribute(file.toPath(), "dos:hidden", true); } catch (IOException ex) { Logger.getLogger(ImageBackgroundLoader.class.getName()).log(Level.SEVERE, null, ex); } return file.getPath(); }
From source file:ml.shifu.shifu.util.CommonUtilsTest.java
public void syncUpEvalTest() throws IOException { ModelConfig config = ModelConfig.createInitModelConfig(".", ALGORITHM.NN, "test", false); config.setModelSetName("shifu"); File file = new File("evals/EvalA"); if (!file.exists()) { FileUtils.forceMkdir(file); }//from w w w .j av a 2s . c o m file = new File("testEval/EvalConfig.json"); FileUtils.touch(file); // CommonUtils.copyEvalConfFromLocalToHDFS(config, "testEval"); Assert.assertTrue(file.exists()); FileUtils.deleteDirectory(new File("ModelSets")); FileUtils.deleteDirectory(new File("evals")); }