List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:ke.co.tawi.babblesms.server.servlet.upload.ContactUpload.java
/** * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *//*from www .ja va2 s. c om*/ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { File uploadedFile = null; List<String> groupUuids = new LinkedList<>(); Account account = new Account(); HttpSession session = request.getSession(false); String username = (String) session.getAttribute(SessionConstants.ACCOUNT_SIGN_IN_KEY); Element element; if ((element = accountsCache.get(username)) != null) { account = (Account) element.getObjectValue(); } // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); // Set up where the files will be stored on disk File repository = new File(System.getProperty("java.io.tmpdir") + File.separator + username); FileUtils.forceMkdir(repository); factory.setRepository(repository); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request try { List<FileItem> items = upload.parseRequest(request); Iterator<FileItem> iter = items.iterator(); FileItem item; while (iter.hasNext()) { item = iter.next(); if (item.isFormField()) { // Here we assume only a Group UUID has been submitted as a text field groupUuids.add(item.getString()); } else { uploadedFile = processUploadedFile(item); } } // end 'while (iter.hasNext())' } catch (FileUploadException e) { logger.error("FileUploadException while getting File Items."); logger.error(e); } // Here we assume that only one file was uploaded // First we inspect if it is ok String feedback = uploadUtil.inspectContactFile(uploadedFile); session.setAttribute(UPLOAD_FEEDBACK, "<p class='error'>" + feedback + "<p>"); response.sendRedirect("addcontact.jsp"); // Process the file into the database if it is ok if (StringUtils.equals(feedback, UPLOAD_SUCCESS)) { uploadUtil.saveContacts(uploadedFile, account, contactDAO, phoneDAO, groupUuids, contactGroupDAO); } }
From source file:main.Configuration.java
/** * Creates the project directories. To be called on tool start. *///from w w w .j av a2 s . co m public static void createProjectDirectories() { try { FileUtils.forceMkdir(new File(OUTPUT_DIRECTORY)); FileUtils.forceMkdir(new File(RESTORED_DIRECTORY)); FileUtils.forceMkdir(new File(SCENARIO_DIRECTORY)); FileUtils.forceMkdir(new File(LIBRARY_DIRECTORY)); } catch (IOException e) { } }
From source file:com.norconex.jef4.log.FileLogManager.java
@Override public final void backup(final String suiteId, final Date backupDate) throws IOException { String date = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(backupDate); File progressFile = getLogFile(suiteId); File backupDir = FileUtil.createDateDirs(new File(logdirBackupBase), backupDate); backupDir = new File(backupDir, "logs"); if (!backupDir.exists()) { try {//from w w w.j a va2s . c o m FileUtils.forceMkdir(backupDir); } catch (IOException e) { throw new JEFException("Cannot create backup directory: " + backupDir, e); } } File backupFile = new File(backupDir + "/" + date + "__" + FileUtil.toSafeFileName(suiteId) + LOG_SUFFIX); if (progressFile.exists()) { FileUtil.moveFile(progressFile, backupFile); } }
From source file:com.netsteadfast.greenstep.util.JReportUtils.java
public static void deploy() throws ServiceException, Exception { logger.info("begin deploy..."); List<TbSysJreport> reports = sysJreportService.findListByParams(null); String reportDeployDirName = Constants.getDeployJasperReportDir() + "/"; File reportDeployDir = new File(reportDeployDirName); try {/*from w ww . j ava 2s .c om*/ if (reportDeployDir.exists()) { logger.warn("delete " + reportDeployDirName); FileUtils.forceDelete(reportDeployDir); } logger.warn("mkdir " + reportDeployDirName); FileUtils.forceMkdir(reportDeployDir); for (TbSysJreport report : reports) { deployReport(report); } } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage().toString()); } reportDeployDir = null; logger.info("end deploy..."); }
From source file:edu.cornell.med.icb.pca.RotationReaderWriter.java
/** * Create a TableCache with the cache located in the * cacheDirectory directory.//from w w w . j a va 2 s .c o m * * @param cacheDirectory the directory in which to store the cached tables * @param splitId the split Id that this reader/writer is associated with * @throws java.io.IOException the cacheDirectory doesn't exist or isn't a directory * or can't be read from or written to. */ public RotationReaderWriter(final File cacheDirectory, final CharSequence datasetEndpointName, final int splitId) throws IOException { super(); final String cacheFilename = cacheDirectory.getCanonicalPath().intern(); this.splitId = splitId; synchronized (cacheFilename) { if (!cacheDirectory.exists()) { FileUtils.forceMkdir(cacheDirectory); } } if (!cacheDirectory.exists()) { throw new IOException("Specified directory does not exist " + cacheDirectory.getCanonicalPath()); } if (!cacheDirectory.isDirectory()) { throw new IOException("Specified file is not a directory " + cacheDirectory.getCanonicalPath()); } if (!cacheDirectory.canRead()) { throw new IOException("Specified directory is not readable " + cacheDirectory.getCanonicalPath()); } if (!cacheDirectory.canWrite()) { throw new IOException("Specified directory is not writable " + cacheDirectory.getCanonicalPath()); } String cacheDirectoryName = cacheDirectory.getCanonicalPath(); if (!cacheDirectoryName.endsWith("/") && !cacheDirectoryName.endsWith("\\")) { cacheDirectoryName += "/"; } cacheDirectoryFile = new File(cacheDirectoryName); // If you change this file name in any way // you will have to change some constants above!!! final String cacheCompoundFilename = cacheDirectoryName + "Rotation-Cache-" + datasetEndpointName + "-Split-" + splitId + ".compound-file"; cfw = new CompoundFileWriter(cacheCompoundFilename); LOG.trace("Opened the compound cache file " + cacheCompoundFilename); cfr = cfw.getCompoundFileReader(); }
From source file:appeng.recipes.loader.RecipeResourceCopier.java
/** * @param destination destination folder to which the recipes are copied to * @param directory the folder to copy.//from ww w . jav a2 s . c om * * @throws URISyntaxException {@see #getResourceListing} * @throws IOException {@see #getResourceListing} and if copying the detected resource to file is not possible * @see {RecipeResourceCopier#copyTo(File)} */ private void copyTo(@Nonnull final String identifier, @Nonnull final File destination, @Nonnull final String directory) throws URISyntaxException, IOException { assert identifier != null; assert destination != null; assert directory != null; final Class<? extends RecipeResourceCopier> copierClass = this.getClass(); final String[] listing = this.getResourceListing(copierClass, directory); for (final String list : listing) { if (list.endsWith(identifier)) { // generate folder before the file is copied so no empty folders will be generated FileUtils.forceMkdir(destination); this.copyFile(destination, directory, list); } else if (!list.contains(".")) { final File subDirectory = new File(destination, list); this.copyTo(identifier, subDirectory, directory + list + "/"); } } }
From source file:de.tarent.maven.plugins.pkg.AbstractMvnPkgPluginTestCase.java
/** {@inheritDoc} */ protected void setUp() throws Exception { super.setUp(); FileUtils.forceMkdir(TARGETDIR); if (CLEANTARGETDIRECTORYBEFORERUN) { FileUtils.cleanDirectory(TARGETDIR); }/*from w w w . jav a 2s. c o m*/ }
From source file:com.alibaba.jstorm.cluster.StormConfig.java
public static String worker_pids_root(Map conf, String id) throws IOException { String ret = worker_root(conf, id) + FILE_SEPERATEOR + "pids"; FileUtils.forceMkdir(new File(ret)); return ret;/*from w w w.j a v a 2 s . c om*/ }
From source file:dynamicrefactoring.interfaz.wizard.search.internal.SearchableTypeIndexer.java
/** * Genera un indice en el directorio del sistema de ficheros cuya ruta viene * dada por {@link #getIndexDir()}./*w w w. j a v a 2 s. c o m*/ * * @param elementType tipo de elemento * @return devuelve el indice * @throws IOException */ protected int index(SearchableType elementType) throws IOException { if (!new File(elementType.getIndexDir()).exists()) { FileUtils.forceMkdir(new File(elementType.getIndexDir())); } return index(elementType, FSDirectory.open(new File(elementType.getIndexDir()))); }
From source file:ddf.security.pdp.realm.xacml.processor.BalanaClient.java
private void initialize(File xacmlPoliciesDirectory) throws PdpException { try {/* ww w. jav a 2s . c o m*/ // Only a single default directory is supported // If the directory path becomes customizable this // functionality should be re-evaluated FileUtils.forceMkdir(xacmlPoliciesDirectory); } catch (IOException e) { LOGGER.error("Unable to create directory: {}", xacmlPoliciesDirectory.getAbsolutePath()); } checkXacmlPoliciesDirectory(xacmlPoliciesDirectory); /** * We currently only support one XACML policies directory, but we may support multiple * directories in the future. */ xacmlPolicyDirectories = new HashSet<>(1); xacmlPolicyDirectories.add(xacmlPoliciesDirectory.getPath()); createPdp(createPdpConfig()); }