List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:de.cosmocode.palava.store.FileSystemStore.java
@Inject FileSystemStore(@Named(FileSystemStoreConfig.DIRECTORY) File directory) throws IOException { Preconditions.checkNotNull(directory, "Directory"); FileUtils.forceMkdir(directory); this.directory = directory; }
From source file:me.neatmonster.spacertk.actions.FileActions.java
/** * Creates a directory// w w w .ja v a 2s . c om * @param directory Directory to create * @return If successful */ @Action(aliases = { "createDirectory", "createDir" }) public boolean createDirectory(final String directory) { try { FileUtils.forceMkdir(new File(directory)); return true; } catch (final IOException e) { e.printStackTrace(); } return false; }
From source file:ch.algotrader.starter.GoogleIntradayDownloader.java
private void retrieve(HttpClient httpclient, String symbol, int interval, int tradingDays) throws IOException, HttpException, FileNotFoundException { GetMethod fileGet = new GetMethod("http://www.google.com/finance/getprices?" + "q=" + symbol + "&i=" + interval + "&p=" + tradingDays + "d" + "&f=d,o,h,l,c,v"); fileGet.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); try {//from w w w. j a v a2s. c o m int status = httpclient.executeMethod(fileGet); if (status == HttpStatus.SC_OK) { BufferedReader reader = new BufferedReader( new InputStreamReader(fileGet.getResponseBodyAsStream())); File parent = new File("files" + File.separator + "google"); if (!parent.exists()) { FileUtils.forceMkdir(parent); } Writer writer = new OutputStreamWriter( new FileOutputStream(new File(parent, symbol + "-" + (interval / 60) + "min.csv"))); writer.write("dateTime,open,high,low,close,vol,barSize,security\n"); try { reader.readLine(); reader.readLine(); reader.readLine(); reader.readLine(); reader.readLine(); reader.readLine(); reader.readLine(); String line; long timestamp = 0; while ((line = reader.readLine()) != null) { String tokens[] = line.split(","); long time; String timeStampString = tokens[0]; if (timeStampString.startsWith("a")) { timestamp = Long.parseLong(timeStampString.substring(1)) * 1000; time = timestamp; } else { time = timestamp + Integer.parseInt(timeStampString) * interval * 1000; } writer.write(Long.toString(time)); writer.write(","); writer.write(tokens[1]); writer.write(","); writer.write(tokens[2]); writer.write(","); writer.write(tokens[3]); writer.write(","); writer.write(tokens[4]); writer.write(","); writer.write(tokens[5]); writer.write(","); writer.write("MIN_" + interval / 60); writer.write(","); writer.write(symbol); writer.write("\n"); } } finally { reader.close(); writer.close(); } } } finally { fileGet.releaseConnection(); } }
From source file:hu.bme.mit.sette.common.tasks.TestSuiteGenerator.java
public void generate() throws Exception { if (!RunnerProjectUtils.getRunnerLogFile(getRunnerProjectSettings()).exists()) { throw new SetteGeneralException("Run the tool on the runner project first (and then parse)"); }/*from w ww . j a v a 2 s . c o m*/ File testsDir = getRunnerProjectSettings().getTestsDirectory(); if (testsDir.exists()) { System.out.println("Removing tests dir"); FileUtils.forceDelete(testsDir); } FileUtils.forceMkdir(testsDir); Serializer serializer = new Persister(new AnnotationStrategy()); // foreach containers for (SnippetContainer container : getSnippetProject().getModel().getContainers()) { // skip container with higher java version than supported if (container.getRequiredJavaVersion().compareTo(getTool().getSupportedJavaVersion()) > 0) { // TODO error handling System.err.println("Skipping container: " + container.getJavaClass().getName() + " (required Java version: " + container.getRequiredJavaVersion() + ")"); continue; } // foreach snippets for (Snippet snippet : container.getSnippets().values()) { File inputsXmlFile = RunnerProjectUtils.getSnippetInputsFile(getRunnerProjectSettings(), snippet); if (!inputsXmlFile.exists()) { System.err.println("Missing: " + inputsXmlFile); continue; } // save current class loader ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); // set snippet project class loader Thread.currentThread().setContextClassLoader(getSnippetProject().getClassLoader()); // read data SnippetInputsXml inputsXml = serializer.read(SnippetInputsXml.class, inputsXmlFile); // set back the original class loader Thread.currentThread().setContextClassLoader(originalClassLoader); if (inputsXml.getResultType() != ResultType.S && inputsXml.getResultType() != ResultType.C && inputsXml.getResultType() != ResultType.NC) { // skip! continue; } if (inputsXml.getGeneratedInputs().size() == 0) { System.err.println("No inputs: " + inputsXmlFile); } Class<?> javaClass = container.getJavaClass(); Package pkg = javaClass.getPackage(); Method method = snippet.getMethod(); StringBuilder java = new StringBuilder(); String classSimpleName = javaClass.getSimpleName() + '_' + method.getName() + "_Tests"; String className = pkg.getName() + "." + classSimpleName; java.append("package ").append(pkg.getName()).append(";\n"); java.append("\n"); java.append("import junit.framework.TestCase;\n"); java.append("import ").append(container.getJavaClass().getName()).append(";\n"); java.append("\n"); java.append("public final class ").append(classSimpleName).append(" extends TestCase {\n"); int i = 0; for (InputElement inputElement : inputsXml.getGeneratedInputs()) { i++; java.append(" public void test_").append(i).append("() throws Exception {\n"); // heap if (StringUtils.isNotBlank(inputElement.getHeap())) { for (String heapLine : inputElement.getHeap().split("\\r?\\n")) { java.append(" ").append(heapLine).append('\n'); } java.append(" \n"); } // try-catch for exception if any expected if (inputElement.getExpected() != null) { java.append(" try {\n"); java.append(" "); appendMethodCall(java, javaClass, method, inputElement); java.append(" fail();\n"); java.append(" } catch (").append(inputElement.getExpected()).append(" e) {\n"); java.append(" }\n"); } else { java.append(" "); appendMethodCall(java, javaClass, method, inputElement); } java.append(" }\n\n"); } java.append("}\n"); File testsFile = new File(testsDir, JavaFileUtils.classNameToSourceFilename(className)); FileUtils.write(testsFile, java.toString()); // import junit.framework.TestCase; // import // hu.bme.mit.sette.snippets._1_basic.B2_conditionals.B2a_IfElse; // // public final class B2a_IfElse_oneParamInt_Tests extends // TestCase { // public void test_1() { // B2a_IfElse.oneParamInt(1); // } // // public void test_2() { // B2a_IfElse.oneParamInt(0); // } // // public void test_3() { // B2a_IfElse.oneParamInt(-1); // } // // public void test_4() { // B2a_IfElse.oneParamInt(12345); // } // } } } }
From source file:com.qcadoo.view.internal.resource.JspResourceResolver.java
private void copyResource(final Resource resource) { if (!resource.isReadable()) { return;/*from w w w.jav a2 s . c om*/ } try { String path = resource.getURI().toString().split("WEB-INF/jsp/")[1]; File file = new File(webappPath + "/WEB-INF/jsp/" + path); if (resource.getInputStream().available() == 0) { FileUtils.forceMkdir(file); } else { if (LOG.isDebugEnabled()) { LOG.debug("Copying " + path + " to " + file.getAbsolutePath()); } OutputStream output = null; try { output = new BufferedOutputStream(new FileOutputStream(file)); IOUtils.copy(resource.getInputStream(), output); } finally { IOUtils.closeQuietly(output); } } } catch (IOException e) { throw new IllegalStateException("Cannot copy resource " + resource, e); } }
From source file:com.ipcglobal.fredimport.process.DistinctCategories.java
/** * Instantiates a new distinct categories.DistinctCategories * * @param properties the properties// w w w. j a va 2s . c o m * @param distinctCategoryItems the distinct category items * @param outputPath the output path * @throws Exception the exception */ public DistinctCategories(Properties properties, Map<Integer, DistinctCategoryItem> distinctCategoryItems, String outputPath) throws Exception { super(); this.properties = properties; this.distinctCategoryItems = distinctCategoryItems; this.outputPath = outputPath; this.tableNameFred = properties.getProperty("tableNameFred").trim(); String outputSubdirRptSql = FredUtils.readfixPath("outputSubdirRptSql", properties); outputPathRptSql = outputPath + outputSubdirRptSql; FileUtils.forceMkdir(new File(outputPathRptSql)); }
From source file:com.textocat.textokit.morph.lemmatizer.util.NormalizedTextWriter.java
@Override public void initialize(UimaContext ctx) throws ResourceInitializationException { super.initialize(ctx); try {/*from w w w .ja va 2 s .c o m*/ FileUtils.forceMkdir(outputDir); } catch (IOException e) { throw new ResourceInitializationException(e); } }
From source file:com.github.tomakehurst.wiremock.common.SingleRootFileSourceTest.java
@Test public void writesTextFileEvenWhenRootIsARelativePath() throws IOException { String relativeRootPath = "./target/tmp/"; FileUtils.forceMkdir(new File(relativeRootPath)); SingleRootFileSource fileSource = new SingleRootFileSource(relativeRootPath); Path fileAbsolutePath = Paths.get(relativeRootPath).toAbsolutePath().resolve("myFile"); fileSource.writeTextFile(fileAbsolutePath.toString(), "stuff"); assertThat(Files.exists(fileAbsolutePath), is(true)); }
From source file:hoot.services.utils.MultipartSerializerTest.java
@Ignore @Test/* ww w.ja va 2 s . com*/ @Category(UnitTest.class) public void TestserializeFGDB() throws Exception { String jobId = "123-456-789"; String wkdirpath = HOME_FOLDER + "/upload/" + jobId; File workingDir = new File(wkdirpath); FileUtils.forceMkdir(workingDir); Assert.assertTrue(workingDir.exists()); String textFieldValue = "0123456789"; File out = new File(wkdirpath + "/fgdbTest.gdb"); FileUtils.write(out, textFieldValue); // MediaType of the body part will be derived from the file. FileDataBodyPart filePart = new FileDataBodyPart("", out, MediaType.APPLICATION_OCTET_STREAM_TYPE); FormDataContentDisposition formDataContentDisposition = new FormDataContentDisposition( "form-data; name=\"eltuploadfile0\"; filename=\"fgdbTest.gdb\""); filePart.setContentDisposition(formDataContentDisposition); FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(filePart); Map<String, String> uploadedFiles = new HashMap<>(); Map<String, String> uploadedFilesPaths = new HashMap<>(); MultipartSerializer.serializeUpload(jobId, "DIR", uploadedFiles, uploadedFilesPaths, multiPart); Assert.assertEquals("GDB", uploadedFiles.get("fgdbTest")); Assert.assertEquals("fgdbTest.gdb", uploadedFilesPaths.get("fgdbTest")); File fgdbpath = new File(wkdirpath + "/fgdbTest.gdb"); Assert.assertTrue(fgdbpath.exists()); File content = new File(wkdirpath + "/fgdbTest.gdb/dummy1.gdbtable"); Assert.assertTrue(content.exists()); FileUtils.forceDelete(workingDir); }
From source file:io.siddhi.extension.io.file.FileSourceBinaryModeTestCase.java
@BeforeMethod public void doBeforeMethod() { count.set(0);// ww w . ja va2 s .c o m try { FileUtils.copyDirectory(sourceRoot, newRoot); movedFiles = new File(moveAfterProcessDir); FileUtils.forceMkdir(movedFiles); } catch (IOException e) { throw new TestException("Failed to copy files from " + sourceRoot.getAbsolutePath() + " to " + newRoot.getAbsolutePath() + " which are required for tests. Hence aborting tests.", e); } }