List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:gov.redhawk.efs.sca.internal.cache.FileCache.java
private void downloadFile(IFileInfo info) throws CoreException { FileOutputStream fileStream = null; InputStream scaInputStream = null; File tmpFile = null;//from w ww . jav a 2 s . c o m File parentDir = new File( FileCache.getTempDir() + "/" + parent.getRoot() + store.getEntry().getAbsolutePath()) .getParentFile(); if (!parentDir.exists()) { try { FileUtils.forceMkdir(parentDir); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, ScaFileSystemPlugin.ID, "File cache error: Failed to create temporary file cache directory " + parentDir, e)); } } localFile = new File(parentDir, store.getEntry().getName()); if (localFile.exists() && localFile.lastModified() == info.getLastModified()) { if ((localFile.isDirectory() && info.isDirectory()) || (localFile.length() == info.getLength())) { return; } } boolean error = false; try { if (info.isDirectory()) { if (!info.exists()) { FileUtils.forceMkdir(localFile); } } else { FileUtils.deleteQuietly(localFile); try { tmpFile = File.createTempFile(localFile.getName(), ".tmp", parentDir); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, ScaFileSystemPlugin.ID, "File cache error: Failed to create temporary file " + localFile, e)); } tmpFile.deleteOnExit(); scaInputStream = createScaInputStream(); fileStream = new FileOutputStream(tmpFile); FileCache.copyLarge(scaInputStream, fileStream); localFile.setExecutable(info.getAttribute(EFS.ATTRIBUTE_EXECUTABLE)); FileUtils.moveFile(tmpFile, localFile); } localFile.setLastModified(info.getLastModified()); } catch (final FileNotFoundException e) { error = true; throw new CoreException( new Status(IStatus.ERROR, ScaFileSystemPlugin.ID, "File cache error: " + localFile, e)); } catch (final IOException e) { error = true; throw new CoreException( new Status(IStatus.ERROR, ScaFileSystemPlugin.ID, "File cache error: " + localFile, e)); } catch (CoreException e) { error = true; throw new CoreException(new Status(IStatus.ERROR, ScaFileSystemPlugin.ID, "File cache error: " + localFile + "\n" + e.getStatus().getMessage(), e.getStatus().getException())); } catch (InterruptedException e) { error = true; throw new CoreException(new Status(IStatus.ERROR, ScaFileSystemPlugin.ID, "File download interrupted: " + localFile, e)); } catch (ExecutionException e) { error = true; throw new CoreException( new Status(IStatus.ERROR, ScaFileSystemPlugin.ID, "File cache error: " + localFile, e)); } catch (TimeoutException e) { error = true; throw new CoreException( new Status(IStatus.ERROR, ScaFileSystemPlugin.ID, "File download time-out: " + localFile, e)); } finally { IOUtils.closeQuietly(fileStream); IOUtils.closeQuietly(scaInputStream); FileUtils.deleteQuietly(tmpFile); if (error) { if (localFile != null && localFile.exists()) { FileUtils.deleteQuietly(localFile); } localFile = null; } } }
From source file:edu.uci.ics.hyracks.hdfs.dataflow.DataflowTest.java
@Override public void setUp() throws Exception { cleanupStores();/*from w w w . j a va2 s.c o m*/ HyracksUtils.init(); FileUtils.forceMkdir(new File(ACTUAL_RESULT_DIR)); FileUtils.cleanDirectory(new File(ACTUAL_RESULT_DIR)); startHDFS(); }
From source file:edu.uci.ics.pregelix.example.dataload.DataLoadTest.java
public void setUp() throws Exception { ClusterConfig.setStorePath(PATH_TO_CLUSTER_STORE); ClusterConfig.setClusterPropertiesPath(PATH_TO_CLUSTER_PROPERTIES); cleanupStores();/*from ww w .j a va 2 s.co m*/ PregelixHyracksIntegrationUtil.init(); LOGGER.info("Hyracks mini-cluster started"); startHDFS(); FileUtils.forceMkdir(new File(EXPECT_RESULT_DIR)); FileUtils.forceMkdir(new File(ACTUAL_RESULT_DIR)); FileUtils.cleanDirectory(new File(EXPECT_RESULT_DIR)); FileUtils.cleanDirectory(new File(ACTUAL_RESULT_DIR)); giraphTestJobGen = new JobGenOuterJoin(job); }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.qPcrMiRnaData.QPcrMirnaLoadAnnotationListener.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); }//from w ww .j a v a2 s.com job.getJobMeta().setParameterValue("SORT_DIR", sort.getAbsolutePath()); job.getJobMeta().setParameterValue("MIRNA_TYPE", "MIRNA_QPCR"); job.getJobMeta().setParameterValue("GPL_ID", platformId); job.getJobMeta().setParameterValue("ANNOTATION_TITLE", annotationTitle); job.getJobMeta().setParameterValue("LOAD_TYPE", "I"); 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:me.springframework.di.gen.dot.DotGenerator.java
/** * Generates a dot file from the {@link Configuration} passed in. * // w ww . j ava2 s .c om * @param config * The configuration. * @param targetFile * The target file. (The file, nor the target directory need to * exist yet.) * @throws GeneratorException * If - for some reason - it turns out to be impossible to * generate the dot file. */ public final void generate(Configuration config, File targetFile) throws GeneratorException { Writer writer = null; try { FileUtils.forceMkdir(targetFile.getParentFile()); writer = new FileWriter(targetFile); FileUtils.writeStringToFile(targetFile, process(config)); } catch (IOException ioe) { throw new GeneratorException(ioe); } finally { IOUtils.closeQuietly(writer); } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.rbmData.RbmLoadAnnotationListener.java
@Override protected void setJobMetadata(Job job) throws Exception { job.getJobMeta().setParameterValue("DATA_LOCATION", dataType.getPath().getAbsolutePath()); File sort = new File(StudySelectionController.getWorkspace().getAbsoluteFile() + File.separator + ".sort"); if (!sort.exists()) { FileUtils.forceMkdir(sort); }/*www .j a v a2 s. c om*/ job.getJobMeta().setParameterValue("SORT_DIR", sort.getAbsolutePath()); job.getJobMeta().setParameterValue("GPL_ID", platformId); job.getJobMeta().setParameterValue("ANNOTATION_TITLE", annotationTitle); job.getJobMeta().setParameterValue("LOAD_TYPE", "I"); 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:com.galenframework.ide.Main.java
private String createFolder(String path) throws IOException { FileUtils.forceMkdir(new File(path)); return path; }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.metabolomicsData.MetabolomicsLoadAnnotationListener.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); }// w w w.ja v a2 s.c o m job.getJobMeta().setParameterValue("SORT_DIR", sort.getAbsolutePath()); job.getJobMeta().setParameterValue("GPL_ID", platformId); job.getJobMeta().setParameterValue("ANNOTATION_TITLE", annotationTitle); job.getJobMeta().setParameterValue("LOAD_TYPE", "I"); 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:eu.openanalytics.rsb.component.DirectoryDepositHandlerTestCase.java
@Test public void handleJobWithPlainFile() throws Exception { final File jobParentFile = new File(FileUtils.getTempDirectory(), UUID.randomUUID().toString()); FileUtils.forceMkdir(jobParentFile); final File zipJobFile = File.createTempFile("test-", ".dat", jobParentFile); FileUtils.copyInputStreamToFile(/* w ww . jav a 2 s. c o m*/ Thread.currentThread().getContextClassLoader().getResourceAsStream("data/fake_data.dat"), zipJobFile); testHandleJob(jobParentFile, zipJobFile); }
From source file:de.akquinet.innovation.play.maven.Play2InstallPlayMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { if (StringUtils.isEmpty(play2version)) { throw new MojoExecutionException("play2version configuration parameter is not set"); }//from w w w. j ava2s . com String debugLogPrefix = "AutoInstall - Play! " + play2version + ' '; File play2basedirFile = new File(play2basedir); File play2home = new File(play2basedirFile, "play-" + play2version); File play2 = new File(play2home, AbstractPlay2Mojo.isWindows() ? "play.bat" : "play"); // Is the requested Play! version already installed? if (play2.isFile() && play2.canExecute()) { getLog().info(debugLogPrefix + "is already installed in " + play2home); return; } getLog().info("Play! " + play2version + " download and installation, please be patient ..."); File zipFile = new File(play2basedirFile, "play-" + play2version + ".zip"); try { URL zipUrl = new URL("http://download.playframework.org/releases/play-" + play2version + ".zip"); FileUtils.forceMkdir(play2basedirFile); // Download getLog().debug(debugLogPrefix + "is downloading to " + zipFile); FileUtils.copyURLToFile(zipUrl, zipFile); // Extract getLog().debug(debugLogPrefix + "is extracting to " + play2basedir); UnArchiver unarchiver = archiverManager.getUnArchiver(zipFile); unarchiver.setSourceFile(zipFile); unarchiver.setDestDirectory(play2basedirFile); unarchiver.extract(); // Prepare File framework = new File(play2home, "framework"); File build = new File(framework, AbstractPlay2Mojo.isWindows() ? "build.bat" : "build"); if (!build.canExecute() && !build.setExecutable(true)) { throw new MojoExecutionException("Can't set " + build + " execution bit"); } if (!play2.canExecute() && !play2.setExecutable(true)) { throw new MojoExecutionException("Can't set " + play2 + " execution bit"); } getLog().debug(debugLogPrefix + "is now installed in " + play2home); } catch (NoSuchArchiverException ex) { throw new MojoExecutionException("Can't auto install Play! " + play2version + " in " + play2basedir, ex); } catch (IOException ex) { try { if (play2home.exists()) { // Clean extracted data FileUtils.forceDelete(play2home); } } catch (IOException ignored) { getLog().warn("Unable to delete extracted Play! distribution after error: " + play2home); } throw new MojoExecutionException("Can't auto install Play! " + play2version + " in " + play2basedir, ex); } catch (ArchiverException e) { throw new MojoExecutionException("Cannot unzip Play " + play2version + " in " + play2basedir, e); } finally { try { if (zipFile.exists()) { // Clean downloaded data FileUtils.forceDelete(zipFile); } } catch (IOException ignored) { getLog().warn("Unable to delete downloaded Play! distribution: " + zipFile); } } }