List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:com.adr.mimame.media.MpgClip.java
private String getCachedMp3File(String url) throws IOException, NoSuchAlgorithmException { if (url == null) { throw new IOException("Null url"); } else if (!"http:".equalsIgnoreCase(url.substring(0, 5)) && !"https:".equalsIgnoreCase(url.substring(0, 6)) && !"ftp:".equalsIgnoreCase(url.substring(0, 4)) && !"jar:".equalsIgnoreCase(url.substring(0, 4))) { // a local file return url; } else {//from ww w. j av a 2 s. com // a remote file FileUtils.forceMkdir(CACHEFOLDER); MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(url.getBytes("UTF-8")); String cachefilename = Base64.getUrlEncoder().encodeToString(md.digest()); File cachefile = new File(CACHEFOLDER, cachefilename + ".mp3"); if (cachefile.exists()) { return cachefile.getPath(); } else { try (InputStream input = new URL(url).openStream(); OutputStream output = new FileOutputStream(cachefile)) { byte[] buffer = new byte[4096]; int n; while ((n = input.read(buffer)) != -1) { output.write(buffer, 0, n); } } return cachefile.getPath(); } } }
From source file:com.doplgangr.secrecy.FileSystem.storage.java
public static java.io.File getRoot() { java.io.File tempDir = new java.io.File(ROOT()); try {// w w w .j a v a 2s . c o m FileUtils.forceMkdir(tempDir); } catch (Exception e) { Util.log(e); } return tempDir; }
From source file:jp.co.tis.gsp.tools.dba.mojo.ExportSchemaMojo.java
@Override protected void executeMojoSpec() throws MojoExecutionException, MojoFailureException { Dialect dialect = DialectFactory.getDialect(url, driver); DialectUtil.setDialect(dialect);//ww w . j av a 2 s . c o m outputDirectoryTemp = new File(outputDirectory.getParentFile(), "_exptmp"); if (outputDirectoryTemp.exists()) { try { FileUtils.cleanDirectory(outputDirectoryTemp); } catch (IOException e) { throw new MojoExecutionException("Can't clean outputDirectory:" + outputDirectoryTemp); } } else { try { FileUtils.forceMkdir(outputDirectoryTemp); } catch (IOException e) { throw new MojoExecutionException("Can't create dump output directory." + outputDirectoryTemp, e); } } getLog().info(schema + "?Export???"); try { ExportParams expParams = createExportParams(); dialect.exportSchema(expParams); } catch (Exception e) { throw new MojoExecutionException("?Export????? ", e); } jarArchiver.addDirectory(outputDirectoryTemp); jarArchiver.setDestFile(new File(outputDirectory, jarName())); try { jarArchiver.createArchive(); } catch (IOException e) { throw new MojoExecutionException("?????", e); } getLog().info(schema + "?Export "); }
From source file:de.blizzy.documentr.markdown.macro.GroovyMacroScanner.java
@PostConstruct public void init() throws IOException { macrosDir = new File(settings.getDocumentrDataDir(), MACROS_DIR_NAME); if (!macrosDir.exists()) { FileUtils.forceMkdir(macrosDir); }/*from w w w . j a v a 2 s .com*/ }
From source file:com.github.brandtg.pantopod.crawler.FileBasedCrawlingEventHandler.java
@Override protected void markError(URI url, int errorCode) throws IOException { File outputRoot = new File(outputDir, url.getHost() + File.separator + url.getPath()); FileUtils.forceMkdir(outputRoot); File errFile = new File(outputRoot, ERR_FILE); if (!errFile.exists()) { try (OutputStream os = new FileOutputStream(errFile)) { IOUtils.write(String.valueOf(errorCode).getBytes(), os); }//from ww w. j ava 2s. c om } }
From source file:com.linkedin.pinot.perf.BenchmarkDictionaryCreation.java
@Setup public void setUp() throws IOException { FileUtils.forceMkdir(INDEX_DIR); for (int i = 0; i < CARDINALITY; i++) { _sortedInts[i] = i;/* www. ja va 2 s .co m*/ _sortedLongs[i] = i; _sortedFloats[i] = i; _sortedDoubles[i] = i; _sortedStrings[i] = String.valueOf(i); } Arrays.sort(_sortedStrings); }
From source file:com.skynetcomputing.skynetclient.persistence.PersistenceManager.java
/** * Starts a new PersistenceManager, using provided directory path as root. * <br>//from ww w .j a v a2 s . co m * Files are saved in the following file system order: * <blockquote><pre> * root\ * Jars\ * (jar_name)_(jar_version).jar * CurrentTask\ * (task_id).task * Data\ * (data_id).data * * </pre></blockquote> * * @param rootDir */ public PersistenceManager(String rootDir) throws IOException { rootDir = rootDir.replace("\\", File.separator).replace("/", File.separator); if (!rootDir.endsWith(File.separator)) { rootDir = rootDir + File.separator; } this.rootDir = rootDir; String propertyKey = MiscUtils.getProperty("resetDatabase"); if (propertyKey != null) { String strReset = MiscUtils.getPropertyOrDefault("resetDatabase", "false"); boolean reset = strReset.equalsIgnoreCase("true"); if (reset) { FileUtils.deleteDirectory(new File(rootDir, JAR_DIR)); } } // Recursively creates all directories if they don't exist. FileUtils.forceMkdir(new File(rootDir, JAR_DIR)); FileUtils.forceMkdir(new File(rootDir, TASK_DIR)); FileUtils.forceMkdir(new File(rootDir, TASK_DIR + DATA_DIR)); }
From source file:Helpers.FileHelper.java
public void deleteDirectory(File path) { if (path.exists()) { try {//from w w w .j ava 2 s . c o m File f = path; FileUtils.cleanDirectory(f); //clean out directory (this is optional -- but good know) FileUtils.forceDelete(f); //delete directory FileUtils.forceMkdir(f); //create directory } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.github.seqware.queryengine.impl.TmpFileStorage.java
/** * <p>Constructor for TmpFileStorage.</p> * * @param i a {@link com.github.seqware.queryengine.impl.SerializationInterface} object. *//*from w ww . jav a2s. c o m*/ public TmpFileStorage(SerializationInterface i) { this.serializer = i; Logger.getLogger(TmpFileStorage.class.getName()) .info("Starting with " + TmpFileStorage.class.getSimpleName() + " in " + tempDir.getAbsolutePath() + " using " + serializer.getClass().getSimpleName()); // make a persistent store exists already, otherwise try to retrieve existing items try { if (!tempDir.exists()) { FileUtils.forceMkdir(tempDir); } else { if (!PERSIST) { this.clearStorage(); } } } catch (IOException ex) { Logger.getLogger(SimplePersistentBackEnd.class.getName()).fatal("IOException starting TmpFileStorage", ex); throw new RuntimeException("Serious problem with file storage"); } }
From source file:edu.hawaii.soest.pacioos.text.SimpleTextSourceTest.java
/** * Start a mock DataTurbine and a MockDataSource, both of which will be connected to * by the SocketTextSource class being tested. * @throws java.lang.Exception/*from w w w .j a v a2s. c o m*/ */ @Before public void setUp() throws Exception { // get the resources directory InputStream propsStream = ClassLoader.getSystemResourceAsStream("test.properties"); Properties properties = new Properties(); try { properties.load(propsStream); testResourcesDirectory = properties.getProperty("test.resources.directory"); } catch (IOException e) { e.printStackTrace(); } // start up a mock DataTurbine instance FileUtils.deleteDirectory(new File("/tmp/dt")); FileUtils.forceMkdir(new File("/tmp/dt")); String[] options = new String[] { "-a", "127.0.0.1:33333", "-H", "/tmp/dt" }; mockDT = Server.launchNewServer(options); log.info("Dataturbine is running on " + mockDT.getAddress()); Thread.sleep(2000); }