List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:com.liferay.maven.arquillian.importer.LiferayPluginTestCase.java
protected static void setupPortalMinimal() { System.setProperty("liferay.version", LIFERAY_VERSION); System.setProperty("liferay.auto.deploy.dir", PORTAL_AUTO_DEPLOY_DIR); System.setProperty("liferay.app.server.deploy.dir", PORTAL_SERVER_DEPLOY_DIR); System.setProperty("liferay.app.server.lib.global.dir", PORTAL_SERVER_LIB_GLOBAL_DIR); System.setProperty("liferay.app.server.portal.dir", SERVER_PORTAL_DIR); try {/* w w w .j a v a2 s . c o m*/ ArchiverManager archiverManager = plexusContainer.lookup(ArchiverManager.class); assertNotNull(archiverManager); FileUtils.forceMkdir(new File(PORTAL_AUTO_DEPLOY_DIR)); FileUtils.forceMkdir(new File(PORTAL_SERVER_DEPLOY_DIR)); FileUtils.forceMkdir(new File(PORTAL_SERVER_LIB_GLOBAL_DIR)); FileUtils.forceMkdir(new File(SERVER_PORTAL_DIR)); final MavenResolverSystem mavenResolverSystem = Maven.configureResolver() .fromClassloaderResource("settings.xml"); File[] dependencies = mavenResolverSystem.loadPomFromClassLoaderResource("liferay-setup.xml") .importRuntimeAndTestDependencies().resolve().withoutTransitivity().asFile(); File warFile = null; for (File file : dependencies) { String fileName = file.getName(); String fileExtension = FilenameUtils.getExtension(fileName); if ("jar".equalsIgnoreCase(fileExtension)) { FileUtils.copyFile(file, new File(PORTAL_SERVER_LIB_GLOBAL_DIR, file.getName())); } else if ("war".equalsIgnoreCase(fileExtension) && fileName.contains("portal-web")) { warFile = file; } } assertNotNull(warFile); // extract portal war UnArchiver unArchiver = archiverManager.getUnArchiver(warFile); unArchiver.setDestDirectory(new File(SERVER_PORTAL_DIR)); unArchiver.setSourceFile(warFile); unArchiver.setOverwrite(false); unArchiver.extract(); setup = true; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.netsteadfast.greenstep.util.JReportUtils.java
public static void deployReport(TbSysJreport report) throws Exception { String reportDeployDirName = Constants.getDeployJasperReportDir() + "/"; File reportDeployDir = new File(reportDeployDirName); try {//from ww w. j av a 2s . c o m if (!reportDeployDir.exists()) { logger.warn("no exists dir, force mkdir " + reportDeployDirName); FileUtils.forceMkdir(reportDeployDir); } } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage().toString()); } logger.info("REPORT-ID : " + report.getReportId()); File reportFile = null; File reportZipFile = null; OutputStream os = null; try { String reportFileFullPath = reportDeployDirName + report.getReportId() + "/" + report.getFile(); String reportZipFileFullPath = reportDeployDirName + report.getReportId() + ".zip"; reportZipFile = new File(reportZipFileFullPath); if (reportZipFile.exists()) { logger.warn("delete " + reportZipFileFullPath); FileUtils.forceDelete(reportZipFile); } os = new FileOutputStream(reportZipFile); IOUtils.write(report.getContent(), os); os.flush(); ZipFile zipFile = new ZipFile(reportZipFileFullPath); zipFile.extractAll(reportDeployDirName); reportFile = new File(reportFileFullPath); if (!reportFile.exists()) { logger.warn("report file is missing : " + reportFileFullPath); return; } if (YesNo.YES.equals(report.getIsCompile()) && report.getFile().endsWith("jrxml")) { logger.info("compile report..."); String outJasper = compileReportToJasperFile(new String[] { reportFileFullPath }, reportDeployDirName + report.getReportId() + "/"); logger.info("out : " + outJasper); } } catch (JRException re) { re.printStackTrace(); logger.error(re.getMessage().toString()); } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage().toString()); } finally { if (os != null) { os.close(); } os = null; reportFile = null; reportZipFile = null; } reportDeployDir = null; }
From source file:de.thb.ue.backend.service.AnswerImageService.java
@Override public void addAnswerImage(Vote vote, MultipartFile answerImage, String evaluationID) { File imageFolder = new File( (workingDirectoryPath.isEmpty() ? "" : (workingDirectoryPath + File.separatorChar)) + evaluationID + File.separatorChar + "images"); try {/*from ww w . ja va 2 s .c o m*/ if (!imageFolder.exists()) { FileUtils.forceMkdir(imageFolder); } BufferedOutputStream stream = new BufferedOutputStream( new FileOutputStream(new File(imageFolder, vote.getId() + ".zip"))); stream.write(answerImage.getBytes()); stream.close(); } catch (IOException e) { //TODO e.printStackTrace(); } }
From source file:com.hp.autonomy.frontend.find.idol.configuration.IdolFindConfigFileServiceTest.java
@SuppressWarnings("ProhibitedExceptionDeclared") @Before//from w w w . j av a 2 s . c om public void setUp() throws Exception { final File directory = new File(TEST_DIR); FileUtils.forceMkdir(directory); final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.addMixIn(ServerConfig.class, ConfigurationFilterMixin.class); objectMapper.addMixIn(ViewConfig.class, ConfigurationFilterMixin.class); final FilterProvider filterProvider = new ConfigFileConfiguration().filterProvider(); idolFindConfigFileService = new IdolFindConfigFileService(); idolFindConfigFileService.setConfigFileLocation("hp.find.home"); idolFindConfigFileService.setConfigFileName("config.json"); idolFindConfigFileService.setDefaultConfigFile("/defaultIdolConfigFile.json"); idolFindConfigFileService.setMapper(objectMapper); idolFindConfigFileService.setTextEncryptor(textEncryptor); idolFindConfigFileService.setFilterProvider(filterProvider); idolFindConfigFileService.init(); }
From source file:de.mprengemann.intellij.plugin.androidicons.util.RefactorHelper.java
public static void copy(Project project, String description, List<File> sources, List<File> targets) throws IOException { final PsiManager instance = PsiManager.getInstance(project); final List<PsiFile> files = new ArrayList<PsiFile>(); final List<PsiDirectory> dirs = new ArrayList<PsiDirectory>(); final List<String> names = new ArrayList<String>(); for (File source : sources) { LocalFileSystem.getInstance().refreshAndFindFileByIoFile(source); final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(source); if (vFile != null) { PsiFile item = instance.findFile(vFile); if (item != null) { files.add(item);/*from w w w. j a v a 2 s. com*/ } } } for (File target : targets) { VirtualFile targetDir = LocalFileSystem.getInstance() .refreshAndFindFileByIoFile(target.getParentFile()); if (targetDir == null) { FileUtils.forceMkdir(target.getParentFile()); targetDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(target.getParentFile()); } if (targetDir != null) { final PsiDirectory dir = instance.findDirectory(targetDir); if (dir != null) { dirs.add(dir); names.add(target.getName()); } } } if (files.size() == dirs.size() && files.size() > 0) { selection = -1; RunnableHelper.runWriteCommand(project, new Runnable() { @Override public void run() { PsiFile file; PsiDirectory dir; String name; for (int i = 0; i < files.size(); i++) { file = files.get(i); dir = dirs.get(i); name = names.get(i); if (checkFileExist(dir, new int[] { selection }, file, name, "Copy")) { continue; } dir.copyFileFrom(name, file); } } }, description); return; } throw new IOException("File not found. No idea why."); }
From source file:com.github.jrh3k5.plugin.maven.l10n.data.internal.AbstractUnitTest.java
/** * Get a reference to a file for testing purposes. * //ww w. j a v a 2 s . c o m * @param filename * The name of the file to be used in the test. * @return A {@link File} reference representing a file that can be used for testing. * @throws IOException * If any errors occur during the test run. */ protected File getTestFile(String filename) throws IOException { final File testFile = new File(String.format("target/test-resources/%s/%s/%s", getClass().getCanonicalName(), testName.getMethodName(), filename)); FileUtils.forceMkdir(testFile.getParentFile()); return testFile; }
From source file:com.github.blindpirate.gogradle.util.IOUtils.java
public static void forceMkdir(File directory) { try {/* www . jav a 2s. c o m*/ FileUtils.forceMkdir(directory); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:io.druid.data.input.impl.PrefetchableTextFilesFirehoseFactoryTest.java
@BeforeClass public static void setup() throws IOException { testDir = File.createTempFile(PrefetchableTextFilesFirehoseFactoryTest.class.getSimpleName(), "testDir"); FileUtils.forceDelete(testDir);/*from ww w . j a v a2 s . c o m*/ FileUtils.forceMkdir(testDir); firehoseTempDir = File.createTempFile(PrefetchableTextFilesFirehoseFactoryTest.class.getSimpleName(), "baseDir"); FileUtils.forceDelete(firehoseTempDir); FileUtils.forceMkdir(firehoseTempDir); for (int i = 0; i < 10; i++) { // Each file is 1390 bytes try (final Writer writer = new BufferedWriter(new FileWriter(new File(testDir, "test_" + i)))) { for (int j = 0; j < 100; j++) { final String a = (20171220 + i) + "," + i + "," + j + "\n"; writer.write(a); } } } }
From source file:com.btoddb.fastpersitentqueue.FpqBatchReaderIT.java
@Before public void setup() throws IOException { theDir = new File("tmp/junitTmp_" + UUID.randomUUID().toString()); FileUtils.forceMkdir(theDir); fpq1 = new Fpq(); fpq1.setQueueName("fpq1"); fpq1.setMaxTransactionSize(1000);/*from www. j ava 2s .c o m*/ fpq1.setMaxMemorySegmentSizeInBytes(100000); fpq1.setMaxJournalFileSize(10000); fpq1.setMaxJournalDurationInMs(30000); fpq1.setFlushPeriodInMs(1000); fpq1.setNumberOfFlushWorkers(4); fpq1.setJournalDirectory(new File(new File(theDir, "fp1"), "journal")); fpq1.setPagingDirectory(new File(new File(theDir, "fp1"), "paging")); }
From source file:com.tc.test.ClassBasedDirectoryTree.java
public File getOrMakeDirectory(Class<?> theClass) throws IOException { File destFile = getDirectory(theClass); if (!destFile.exists()) FileUtils.forceMkdir(destFile); return destFile; }