List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:dynamicrefactoring.domain.xml.AddRefactoringObject.java
/** * Crea el directorio de la refactorizacion si no existe ya. *//*www .jav a2 s .c om*/ private void createRefactoringDefinitionDirectory() { try { if (!refactoring.getRefactoringDirectoryFile().exists()) { FileUtils.forceMkdir(refactoring.getRefactoringDirectoryFile()); } } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:dk.itst.oiosaml.sp.IntegrationTests.java
@Before public final void setUpServer() throws Exception { tmpdir = new File(System.getProperty("java.io.tmpdir") + "/oiosaml-" + Math.random()); tmpdir.mkdir();//from w ww .j a v a2 s . c o m FileUtils.forceMkdir(new File(tmpdir, "metadata/IdP")); FileUtils.forceMkdir(new File(tmpdir, "metadata/SP")); credential = TestHelper.getCredential(); EntityDescriptor idpDescriptor = TestHelper.buildEntityDescriptor(credential); FileOutputStream fos = new FileOutputStream(new File(tmpdir, "metadata/IdP/gen.xml")); IOUtils.write(XMLHelper.nodeToString(SAMLUtil.marshallObject(idpDescriptor)).getBytes(), fos); fos.close(); EntityDescriptor spDescriptor = (EntityDescriptor) SAMLUtil .unmarshallElement(getClass().getResourceAsStream("/dk/itst/oiosaml/sp/SPMetadata.xml")); fos = new FileOutputStream(new File(tmpdir, "metadata/SP/SPMetadata.xml")); IOUtils.write(XMLHelper.nodeToString(SAMLUtil.marshallObject(spDescriptor)).getBytes(), fos); fos.close(); spMetadata = new SPMetadata(spDescriptor, SAMLConstants.SAML20P_NS); idpMetadata = new IdpMetadata(SAMLConstants.SAML20P_NS, idpDescriptor); fos = new FileOutputStream(new File(tmpdir, "oiosaml-sp.log4j.xml")); IOUtils.write( "<!DOCTYPE log4j:configuration SYSTEM \"http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/log4j.dtd\"><log4j:configuration xmlns:log4j=\"http://jakarta.apache.org/log4j/\" debug=\"false\"></log4j:configuration>", fos); fos.close(); Properties props = new Properties(); props.setProperty(Constants.PROP_CERTIFICATE_LOCATION, "keystore"); props.setProperty(Constants.PROP_CERTIFICATE_PASSWORD, "password"); props.setProperty(Constants.PROP_LOG_FILE_NAME, "oiosaml-sp.log4j.xml"); props.setProperty(SAMLUtil.OIOSAML_HOME, tmpdir.getAbsolutePath()); props.setProperty(Constants.PROP_SESSION_HANDLER_FACTORY, SingleVMSessionHandlerFactory.class.getName()); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(null, null); ks.setKeyEntry("oiosaml", credential.getPrivateKey(), "password".toCharArray(), new Certificate[] { TestHelper.getCertificate(credential) }); OutputStream bos = new FileOutputStream(new File(tmpdir, "keystore")); ks.store(bos, "password".toCharArray()); bos.close(); props.setProperty(Constants.PROP_ASSURANCE_LEVEL, "2"); props.setProperty(Constants.PROP_IGNORE_CERTPATH, "true"); fos = new FileOutputStream(new File(tmpdir, "oiosaml-sp.properties")); props.store(fos, "Generated"); fos.close(); SAMLConfiguration.setSystemConfiguration(null); IdpMetadata.setMetadata(null); SPMetadata.setMetadata(null); System.setProperty(SAMLUtil.OIOSAML_HOME, tmpdir.getAbsolutePath()); server = new Server(8808); WebAppContext wac = new WebAppContext(); wac.setClassLoader(Thread.currentThread().getContextClassLoader()); wac.setContextPath("/saml"); wac.setWar("webapp/"); server.setHandler(wac); server.start(); client = new WebClient(); client.setRedirectEnabled(false); client.setThrowExceptionOnFailingStatusCode(false); handler = new RedirectRefreshHandler(); client.setRefreshHandler(handler); }
From source file:de.flapdoodle.embed.memcached.MemcachedExecutableTest.java
@Test public void testStartMemcachedOnNonFreePort() throws IOException, InterruptedException { MemcachedConfig memcachedConfig = new MemcachedConfig(Version.Main.PRODUCTION, 12346); final File outer = new File(new PropertyOrPlatformTempDir().asFile(), "outer"); FileUtils.forceMkdir(outer); IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(Command.MemcacheD).artifactStore( new ArtifactStoreBuilder().defaultsWithoutCache(Command.MemcacheD).tempDir(new IDirectory() { @Override//from w w w.j a v a 2 s . c o m public File asFile() { return outer; } @Override public boolean isGenerated() { return false; } })).build(); MemcachedExecutable memcachedExe = MemcachedStarter.getInstance(runtimeConfig).prepare(memcachedConfig); MemcachedProcess memcached = memcachedExe.start(); boolean innerMongodCouldNotStart = false; Thread.sleep(500); MemcachedExecutable innerExe = MemcachedStarter .getInstance(new RuntimeConfigBuilder().defaults(Command.MemcacheD).build()) .prepare(memcachedConfig); try { MemcachedProcess innerMemcached = innerExe.start(); } catch (IOException iox) { innerMongodCouldNotStart = true; } finally { innerExe.stop(); Assert.assertTrue("inner Mongod could not start", innerMongodCouldNotStart); memcached.stop(); memcachedExe.stop(); } }
From source file:com.lioland.harmony.web.controller.FileController.java
/** * ************************************************* * URL: /rest/controller/upload upload(): receives files * * @param request : MultipartHttpServletRequest auto passed * @param response : HttpServletResponse auto passed * @return LinkedList<FileMeta> as json format * ************************************************** *//*from ww w . j a v a 2s . c o m*/ @RequestMapping(value = "/file-upload", method = RequestMethod.POST) public @ResponseBody LinkedList<FileMeta> upload(HttpServletRequest req, HttpServletResponse response) { MultipartHttpServletRequest request = (MultipartHttpServletRequest) req; //1. build an iterator Iterator<String> itr = request.getFileNames(); MultipartFile mpf = null; //2. get each file while (itr.hasNext()) { //2.1 get next MultipartFile mpf = request.getFile(itr.next()); System.out.println(mpf.getOriginalFilename() + " uploaded! " + files.size()); //2.2 if files > 10 remove the first from the list if (files.size() >= 10) { files.pop(); } //2.3 create new fileMeta fileMeta = new FileMeta(); fileMeta.setFileName(mpf.getOriginalFilename()); fileMeta.setFileSize(mpf.getSize() / 1024 + " Kb"); fileMeta.setFileType(mpf.getContentType()); try { fileMeta.setBytes(mpf.getBytes()); File folder = new File("D:\\GitHub\\Harmony\\Harmony\\Web\\src\\main\\webapp\\resources\\files"); FileUtils.forceMkdir(folder); FileCopyUtils.copy(mpf.getBytes(), new FileOutputStream(new File(folder, mpf.getOriginalFilename()))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //2.4 add to files files.add(fileMeta); } // result will be like this // [{"fileName":"app_engine-85x77.png","fileSize":"8 Kb","fileType":"image/png"},...] return files; }
From source file:com.googlecode.fightinglayoutbugs.AbstractLayoutBugDetector.java
private File saveScreenshot(int[][] pixels) { File screenshotFile = null;/*from ww w . jav a 2s.c om*/ final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String prefix = getClass().getSimpleName(); if (prefix.startsWith("Detect")) { prefix = prefix.substring("Detect".length()); } boolean success = false; try { if (!screenshotDir.exists()) { FileUtils.forceMkdir(screenshotDir); } screenshotFile = File.createTempFile(prefix + "_" + df.format(new Date()) + ".", ".png", screenshotDir); ImageHelper.pixelsToPngFile(pixels, screenshotFile); success = true; } catch (Exception e) { LOG.error("Failed to save screenshot.", e); } finally { if (!success) { screenshotFile = null; } } return screenshotFile; }
From source file:com.funambol.server.config.ConfigurationTest.java
@Override protected void setUp() throws Exception { File initialPlugin = new File(funambolHome, "com/funambol/server/config/Configuration/plugin/initial-plugins"); FileUtils.forceMkdir(runtimePluginDir); FileUtils.cleanDirectory(runtimePluginDir); FileUtils.copyDirectory(initialPlugin, runtimePluginDir, new WildcardFileFilter("*.xml")); ////from w w w .ja v a 2 s . c om // This is required since if the plugin xml files used in the tests are // downloaded from SVN repository, they have the same timestamp so the changes // are not correctly detected by the DirectoryMonitor. In this way we are sure // the timestamp is different (touch uses the current timestamp and of course the // files - in src/test/data/com/funambol/server/config/Configuration/pluging/test-1 - // are downloaded previously) // File[] files = runtimePluginDir.listFiles(); for (File file : files) { FileUtils.touch(file); } Configuration.getConfiguration(); }
From source file:com.legstar.coxb.gen.AbstractCoxbGenTest.java
/** * The common target folder for generated binding files. * // www . j a v a 2s . c om * @param schemaName the schema name * @return a folder for binding files * @throws IOException if target folder cannot be created */ public File getTargetFolder(final String schemaName) throws IOException { File targetFolder = new File(GEN_SRC_DIR, GEN_SRC_SUBDIR + '/' + schemaName + "/bind/"); FileUtils.forceMkdir(targetFolder); return targetFolder; }
From source file:ch.admin.suis.msghandler.common.ClientConfigurationFactoryTest.java
@Override public void setUp() throws Exception { super.setUp(); TEMP_DIRS.forEach((dir) -> {/*from w w w .ja va 2s .com*/ try { FileUtils.forceMkdir(dir); } catch (IOException ex) { // ignore } }); }
From source file:hoot.services.controllers.ingest.FileUploadResourceTest.java
@Test @Category(UnitTest.class) public void TestBuildNativeRequestFgdbOgr() throws Exception { String jobId = "test-id-123"; String wkdirpath = homeFolder + "/upload/" + jobId; File workingDir = new File(wkdirpath); FileUtils.forceMkdir(workingDir); org.junit.Assert.assertTrue(workingDir.exists()); File srcFile = new File(homeFolder + "/test-files/service/FileUploadResourceTest/fgdb_ogr.zip"); File destFile = new File(wkdirpath + "/fgdb_ogr.zip"); FileUtils.copyFile(srcFile, destFile); org.junit.Assert.assertTrue(destFile.exists()); FileUploadResource res = new FileUploadResource(); // Let's test zip JSONArray results = new JSONArray(); JSONObject zipStat = new JSONObject(); res._buildNativeRequest(jobId, "fgdb_ogr", "zip", "fgdb_ogr.zip", results, zipStat); org.junit.Assert.assertTrue(results.size() == 2); for (Object oRes : results) { JSONObject cnt = (JSONObject) oRes; if (cnt.get("type").toString().equals("FGDB_ZIP")) { org.junit.Assert.assertTrue(cnt.get("name").toString().equals("fgdb_ogr/DcGisRoads.gdb")); } else if (cnt.get("type").toString().equals("OGR_ZIP")) { org.junit.Assert//w w w . ja v a 2s. com .assertTrue(cnt.get("name").toString().equals("fgdb_ogr/jakarta_raya_coastline.shp")); } } FileUtils.forceDelete(workingDir); }
From source file:com.talis.hadoop.rdf.merge.IndexMergeReducer.java
@Override public void setup(Context context) { LOG.info("Configuring index merge reducer"); taskAttemptID = context.getTaskAttemptID(); try {/* w ww .j a v a2 s. c om*/ fs = FileSystem.get(FileOutputFormat.getOutputPath(context).toUri(), context.getConfiguration()); outRemote = FileOutputFormat.getWorkOutputPath(context); LOG.debug("Remote output path is {}", outRemote); String workDirRoot = context.getConfiguration().get(LOCAL_WORK_ROOT_DIR, System.getProperty("java.io.tmpdir")); LOG.debug("Local work root directory is {}", workDirRoot); localWorkDir = new File(workDirRoot, context.getJobName() + "_" + context.getJobID() + "_" + taskAttemptID); FileUtils.forceMkdir(localWorkDir); LOG.info("Local work directory is {}", localWorkDir); localShards = new Path(localWorkDir.getAbsolutePath(), "shards"); localShardsDir = new File(localShards.toString()); FileUtils.forceMkdir(localShardsDir); LOG.info("Local shards directory is {}", localShardsDir); outLocal = new Path(localWorkDir.getAbsolutePath(), "combined"); File combinedDir = new File(outLocal.toString()); FileUtils.forceMkdir(combinedDir); LOG.info("Local combined index directory is {}", combinedDir); optimizeOutput = context.getConfiguration().getBoolean(OPTIMIZE_OUTPUT, true); LOG.info("Output optimization false is set to {}", optimizeOutput); combined = FSDirectory.open(combinedDir); writer = new IndexWriter(combined, new StopAnalyzer(Version.LUCENE_29), true, IndexWriter.MaxFieldLength.UNLIMITED); } catch (Exception e) { throw new TDBLoader3Exception(e); } }