List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:jenkins.branch.RewindableFileOutputStream.java
private synchronized OutputStream current() throws IOException { if (current == null) { if (!closed) { FileUtils.forceMkdir(out.getParentFile()); try { current = new FileOutputStream(out, initialAppend); initialAppend = false;//w ww . j a v a2s.c om } catch (FileNotFoundException e) { throw new IOException("Failed to open " + out, e); } } else { throw new IOException(out.getName() + " stream is closed"); } } return current; }
From source file:com.github.jrh3k5.flume.mojo.plugin.AbstractFlumePluginMojoITest.java
/** * Create a directory.//www. j ava 2 s .c om * * @param directory * The directory to be created. */ private static void createDirectory(File directory) { try { FileUtils.forceMkdir(directory); } catch (IOException e) { throw new IllegalStateException("Unable to create directory: " + directory, e); } }
From source file:io.druid.data.input.impl.SqlFirehoseTest.java
@Before public void setup() throws IOException { TEST_DIR = File.createTempFile(SqlFirehose.class.getSimpleName(), "testDir"); FileUtils.forceDelete(TEST_DIR);//from w ww . j av a 2 s . c o m FileUtils.forceMkdir(TEST_DIR); final List<Map<String, Object>> inputTexts = ImmutableList.of( ImmutableMap.of("x", "foostring1", "timestamp", 2000), ImmutableMap.of("x", "foostring2", "timestamp", 2000)); List<FileInputStream> testFile = new ArrayList<>(); this.objectMapper = new ObjectMapper(new SmileFactory()); int i = 0; for (Map m : inputTexts) { File file = new File(TEST_DIR, "test_" + i++); try (FileOutputStream fos = new FileOutputStream(file)) { final JsonGenerator jg = objectMapper.getFactory().createGenerator(fos); jg.writeStartArray(); jg.writeObject(m); jg.writeEndArray(); jg.close(); testFile.add(new FileInputStream(file)); } } this.fileList = testFile; parser = new MapInputRowParser(new TimeAndDimsParseSpec(new TimestampSpec("timestamp", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("x")), null, null))); this.inputs = inputTexts; }
From source file:hoot.services.controllers.ingest.BasemapResourceTest.java
@Test @Category(UnitTest.class) public void TestgetBasemapList() throws Exception { BasemapResource mapRes = new BasemapResource(); File f = new File(mapRes._tileServerPath + "/BASEMAP/TestMap"); FileUtils.forceMkdir(f); JSONObject cont = new JSONObject(); cont.put("jobid", "123-456-789"); cont.put("path", "/projects/hoot/ingest/processed/BASEMAP/TestMap"); File file = new File(mapRes._ingestStagingPath + "/BASEMAP/TestMap.enabled"); FileUtils.writeStringToFile(file, cont.toJSONString()); File f2 = new File(mapRes._tileServerPath + "/BASEMAP/TestMap2"); FileUtils.forceMkdir(f2);/* w ww . j a va2 s. c o m*/ File file2 = new File(mapRes._ingestStagingPath + "/BASEMAP/TestMap2.enabled"); FileUtils.writeStringToFile(file2, cont.toJSONString()); JSONArray res = mapRes._getBasemapList(); boolean found = false; for (Object oMap : res) { JSONObject map = (JSONObject) oMap; if (map.get("name").toString().equals("TestMap")) { found = true; break; } } org.junit.Assert.assertTrue(found); FileUtils.forceDelete(f); FileUtils.forceDelete(f2); }
From source file:net.sourceforge.atunes.kernel.modules.lyrics.LyricsCache.java
/** * Private getter for lyricsCacheDir. If dir does not exist, it's created * //from w w w. jav a 2 s. c o m * @return * @throws IOException */ private synchronized static File getLyricsCacheDir() throws IOException { if (!lyricsCacheDir.exists()) FileUtils.forceMkdir(lyricsCacheDir); return lyricsCacheDir; }
From source file:eu.dime.userresolver.service.user.OrmLiteUserProvider.java
public OrmLiteUserProvider() { properties = new Properties(); try {//from w ww . j ava 2 s .co m properties.load(OrmLiteUserProvider.class.getResourceAsStream(PROPERTIES_URI)); appFolder = new File( FilenameUtils.concat(FileUtils.getUserDirectoryPath(), properties.getProperty("app.folder"))); FileUtils.forceMkdir(appFolder); } catch (IOException e) { LOG.error("Unable to create app folder", e); throw new RuntimeException("Unable to load properties", e); } try { connectionSource = new JdbcConnectionSource( "jdbc:sqlite:" + FilenameUtils.concat(appFolder.getAbsolutePath(), "resolver.db")); userDao = DaoManager.createDao(connectionSource, User.class); // schema upgrade "hack" try { userDao.executeRaw("ALTER TABLE `users` ADD COLUMN key STRING;"); } catch (SQLException e) { LOG.info("Schema update failed. Already updated?"); } TableUtils.createTableIfNotExists(connectionSource, User.class); } catch (SQLException e) { LOG.error("Unable to create database", e); throw new RuntimeException("Unable to create database", e); } }
From source file:net.pms.logging.DebugLogPathDefiner.java
/** * @return first writable folder in the following order: * <p>//www . j ava 2 s. c om * 1. (On Linux only) path to {@code /var/log/ps3mediaserver/%USERNAME%/}. * </p> * <p> * 2. Path to profile folder ({@code ~/.config/PMS/} on Linux, {@code %ALLUSERSPROFILE%\PMS} on Windows and * {@code ~/Library/Application Support/PMS/} on Mac). * </p> * <p> * 3. Path to user-defined temp folder specified by {@code temp_directory} param in PMS.conf. * </p> * <p> * 4. Path to system temp folder. * </p> */ @Override public String getPropertyValue() { if (Platform.isLinux()) { final String username = System.getProperty("user.name"); final File logDirectory = new File("/var/log/ps3mediaserver/" + username + "/"); try { FileUtils.forceMkdir(logDirectory); if (FileUtil.isDirectoryWritable(logDirectory)) { return logDirectory.getAbsolutePath(); } } catch (IOException ex) { // Could not create directory, possible permissions problems. } } // Check if profile directory is writable. final File logDirectory = new File(configuration.getProfileDirectory()); if (FileUtil.isDirectoryWritable(logDirectory)) { return logDirectory.getAbsolutePath(); } // Try user-defined temp folder or fallback to system temp folder, which should be writable. try { return configuration.getTempFolder().getAbsolutePath(); } catch (IOException ex) { return System.getProperty("java.io.tmpdir"); } }
From source file:com.github.neoio.nio.impl.SimpleDirectory.java
@Override public File toFile() throws NetIOException { try {/*w ww .j av a2s.c o m*/ File file = new File(dir); FileUtils.forceMkdir(file); return file; } catch (IOException e) { throw new NetIOException(e); } }
From source file:com.orange.mmp.dao.flf.MidletDaoFlfImpl.java
public Midlet createOrUdpdate(Midlet midlet) throws MMPDaoException { if (midlet == null || midlet.getJadLocation() == null || midlet.getJarLocation() == null || midlet.getType() == null) { throw new MMPDaoException("missing or bad data access object"); }//from www . j a v a 2 s . c o m try { this.lock.lock(); File typeFolder = new File(this.path, midlet.getType()); if (!typeFolder.isDirectory()) FileUtils.forceMkdir(typeFolder); File jadFile = new File(new URI(midlet.getJadLocation())); FileUtils.copyFileToDirectory(jadFile, typeFolder); File jarFile = new File(new URI(midlet.getJarLocation())); FileUtils.copyFileToDirectory(jarFile, typeFolder); FileUtils.touch(new File(this.path)); } catch (IOException ioe) { throw new MMPDaoException("failed to add PFM : " + ioe.getMessage()); } catch (URISyntaxException use) { throw new MMPDaoException("failed to add PFM : " + use.getMessage()); } finally { this.lock.unlock(); } return midlet; }
From source file:ml.shifu.shifu.actor.NormalizeDataActorTest.java
@Test public void testActor() throws IOException, InterruptedException { File tmpDir = new File("./tmp"); if (tmpDir.isDirectory()) { FileUtils.deleteDirectory(tmpDir); }// w w w. j a va2 s .co m FileUtils.forceMkdir(tmpDir); ActorRef normalizeRef = actorSystem.actorOf(new Props(new UntypedActorFactory() { private static final long serialVersionUID = 6777309320338075269L; public UntypedActor create() throws IOException { return new NormalizeDataActor(modelConfig, columnConfigList, new AkkaExecStatus(true)); } }), "normalize-calculator"); List<Scanner> scanners = ShifuFileUtils.getDataScanners( "src/test/resources/example/cancer-judgement/DataStore/DataSet1", SourceType.LOCAL); normalizeRef.tell(new AkkaActorInputMessage(scanners), normalizeRef); while (!normalizeRef.isTerminated()) { Thread.sleep(5000); } File outputFile = new File("./tmp/NormalizedData"); Assert.assertTrue(outputFile.exists()); for (Scanner scanner : scanners) { scanner.close(); } }