List of usage examples for org.apache.commons.io FileUtils forceDelete
public static void forceDelete(File file) throws IOException
From source file:jp.primecloud.auto.process.lb.PuppetLoadBalancerProcess.java
protected void backupManifest(File manifestFile) { if (!manifestFile.exists()) { return;/* ww w . j a v a 2 s. co m*/ } // ?? File backupDir = new File(manifestDir, "backup"); File backupFile = new File(backupDir, manifestFile.getName()); try { if (!backupDir.exists()) { backupDir.mkdir(); } if (backupFile.exists()) { FileUtils.forceDelete(backupFile); } FileUtils.moveFile(manifestFile, backupFile); } catch (IOException e) { // ?? log.warn(e.getMessage()); } }
From source file:jp.primecloud.auto.process.lb.PuppetLoadBalancerProcess.java
protected void deleteManifest(File manifestFile) { // ?//from w w w . java 2s . c o m if (!manifestFile.exists()) { return; } try { FileUtils.forceDelete(manifestFile); } catch (IOException e) { // ? log.warn(e.getMessage()); } }
From source file:ZipUtilTest.java
public void testUnwrapSingleRootWithStructure() throws Exception { File src = new File(getClass().getResource("demo-single-root-dir.zip").getPath()); File destDir = File.createTempFile("tempDir", null); try {/*from ww w. j a v a2 s .co m*/ destDir.delete(); destDir.mkdir(); ZipUtil.unwrap(src, destDir); assertTrue((new File(destDir, "b.txt")).exists()); assertTrue((new File(destDir, "bad.txt")).exists()); assertTrue((new File(destDir, "b")).exists()); assertTrue((new File(new File(destDir, "b"), "c.txt")).exists()); } finally { FileUtils.forceDelete(destDir); } }
From source file:jp.primecloud.auto.process.puppet.PuppetNodesProcess.java
protected void backupManifest(Long instanceNo) { Instance instance = instanceDao.read(instanceNo); File manifestFile = new File(manifestDir, instance.getFqdn() + ".base_coordinate.pp"); if (!manifestFile.exists()) { return;//from ww w. java 2 s. c om } // ?? File backupDir = new File(manifestDir, "backup"); File backupFile = new File(backupDir, manifestFile.getName()); try { if (!backupDir.exists()) { backupDir.mkdir(); } if (backupFile.exists()) { FileUtils.forceDelete(backupFile); } FileUtils.moveFile(manifestFile, backupFile); } catch (IOException e) { // ?? log.warn(e.getMessage()); } }
From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.TestConsoleLicenseGenerator.java
@Test public void testInitializeLicenseCreator04() throws Exception { this.resetLicenseCreator(); String fileName = "testInitializeLicenseCreator04.properties"; File file = new File(fileName); if (file.exists()) FileUtils.forceDelete(file); File keyFile = new File("testInitializeLicenseCreator04.key"); FileUtils.writeStringToFile(keyFile, "aKey"); FileUtils.writeStringToFile(file,/*w ww . java 2s . c o m*/ "net.nicholaswilliams.java.licensing.privateKeyFile=testInitializeLicenseCreator04.key\r\n" + "net.nicholaswilliams.java.licensing.privateKeyPassword=testPassword04"); this.console.cli = EasyMock.createMockBuilder(CommandLine.class).withConstructor() .addMockedMethod("hasOption", String.class).addMockedMethod("getOptionValue", String.class) .createStrictMock(); EasyMock.expect(this.console.cli.hasOption("config")).andReturn(true); EasyMock.expect(this.console.cli.getOptionValue("config")).andReturn(fileName); EasyMock.replay(this.console.cli, this.device); try { this.console.initializeLicenseCreator(); PrivateKeyDataProvider key = this.getPrivateKeyDataProvider(); assertNotNull("The key provider should not be null.", key); assertSame("The key provider is not correct.", FilePrivateKeyDataProvider.class, key.getClass()); assertEquals("The file is not correct.", keyFile.getAbsolutePath(), ((FilePrivateKeyDataProvider) key).getPrivateKeyFile().getAbsolutePath()); PasswordProvider password = this.getPasswordProvider(); assertNotNull("The password provider should not be null.", password); assertArrayEquals("The password is not correct.", "testPassword04".toCharArray(), password.getPassword()); } finally { LicenseCreatorProperties.setPrivateKeyDataProvider(null); LicenseCreatorProperties.setPrivateKeyPasswordProvider(null); this.resetLicenseCreator(); FileUtils.forceDelete(file); FileUtils.forceDelete(keyFile); EasyMock.verify(this.console.cli); } }
From source file:de.interactive_instruments.ShapeChange.Target.ArcGISWorkspace.ArcGISWorkspace.java
public void initialise(PackageInfo p, Model m, Options o, ShapeChangeResult r, boolean diagOnly) throws ShapeChangeAbortException { appSchemaPkg = p;//from w w w . j av a2s. c o m model = m; options = o; result = r; // initialize mappings this.lengthMappingByTypeName.put("esriFieldTypeInteger", 0); this.lengthMappingByTypeName.put("esriFieldTypeDouble", 0); this.lengthMappingByTypeName.put("esriFieldTypeDate", 0); this.precisionMappingByTypeName.put("esriFieldTypeString", 0); this.precisionMappingByTypeName.put("esriFieldTypeInteger", 9); this.precisionMappingByTypeName.put("esriFieldTypeDouble", 10); this.precisionMappingByTypeName.put("esriFieldTypeDate", 0); this.scaleMappingByTypeName.put("esriFieldTypeString", 0); this.scaleMappingByTypeName.put("esriFieldTypeInteger", 0); this.scaleMappingByTypeName.put("esriFieldTypeDouble", 6); this.scaleMappingByTypeName.put("esriFieldTypeDate", 0); // get output location outputDirectory = options.parameter(this.getClass().getName(), PARAM_OUTPUT_DIR); if (outputDirectory == null) outputDirectory = options.parameter("outputDirectory"); if (outputDirectory == null) outputDirectory = options.parameter("."); String outputFilename = appSchemaPkg.name().replace("/", "_").replace(" ", "_") + ".eap"; // parse default length parameter String defaultLengthParamValue = options.parameter(this.getClass().getName(), PARAM_LENGTH_TAGGED_VALUE_DEFAULT); if (defaultLengthParamValue != null) { try { int length = Integer.parseInt(defaultLengthParamValue); this.lengthTaggedValueDefault = length; } catch (NumberFormatException e) { result.addError(this, 13); } } // Check if we can use the output directory; create it if it // does not exist outputDirectoryFile = new File(outputDirectory); boolean exi = outputDirectoryFile.exists(); if (!exi) { try { FileUtils.forceMkdir(outputDirectoryFile); } catch (IOException e) { result.addError(this, 5, e.getMessage()); e.printStackTrace(System.err); } exi = outputDirectoryFile.exists(); } boolean dir = outputDirectoryFile.isDirectory(); boolean wrt = outputDirectoryFile.canWrite(); boolean rea = outputDirectoryFile.canRead(); if (!exi || !dir || !wrt || !rea) { result.addFatalError(this, 1, outputDirectory); throw new ShapeChangeAbortException(); } File outputFile = new File(outputDirectoryFile, outputFilename); // check if output file already exists - if so, attempt to delete it exi = outputFile.exists(); if (exi) { result.addInfo(this, 2, outputFilename, outputDirectory); try { FileUtils.forceDelete(outputFile); result.addInfo(this, 3); } catch (IOException e) { result.addInfo(this, 4, e.getMessage()); e.printStackTrace(System.err); } } // read workspace template // String pathToWorkspaceTemplateFileInput = options.parameter(this // .getClass().getName(), PARAM_WORKSPACE_TEMPLATE); // File workspaceTemplateFileInput = null; // // if (pathToWorkspaceTemplateFileInput == null) { // result.addFatalError(this, 6); // throw new ShapeChangeAbortException(); // } else { // workspaceTemplateFileInput = new File( // pathToWorkspaceTemplateFileInput); // if (!workspaceTemplateFileInput.canRead()) { // result.addFatalError(this, 7, pathToWorkspaceTemplateFileInput); // throw new ShapeChangeAbortException(); // } // } workspaceTemplateFilePath = options.parameter(this.getClass().getName(), PARAM_WORKSPACE_TEMPLATE); if (workspaceTemplateFilePath == null) { workspaceTemplateFilePath = options.parameter(PARAM_WORKSPACE_TEMPLATE); } // if no path is provided, use the directory of the default template if (workspaceTemplateFilePath == null) { workspaceTemplateFilePath = WORKSPACE_TEMPLATE_URL; result.addInfo(this, 9, PARAM_WORKSPACE_TEMPLATE, WORKSPACE_TEMPLATE_URL); } // copy template file either from remote or local URI if (workspaceTemplateFilePath.toLowerCase().startsWith("http")) { try { URL templateUrl = new URL(workspaceTemplateFilePath); FileUtils.copyURLToFile(templateUrl, outputFile); } catch (MalformedURLException e1) { result.addFatalError(this, 6, workspaceTemplateFilePath, e1.getMessage()); throw new ShapeChangeAbortException(); } catch (IOException e2) { result.addFatalError(this, 8, e2.getMessage()); throw new ShapeChangeAbortException(); } } else { File workspacetemplate = new File(workspaceTemplateFilePath); if (workspacetemplate.exists()) { try { FileUtils.copyFile(workspacetemplate, outputFile); } catch (IOException e) { result.addFatalError(this, 8, e.getMessage()); throw new ShapeChangeAbortException(); } } else { result.addFatalError(this, 7, workspacetemplate.getAbsolutePath()); throw new ShapeChangeAbortException(); } } // File workspaceTemplateFileInput = new File( // workspaceTemplateFilePath); // if (!workspaceTemplateFileInput.canRead()) { // result.addFatalError(this, 7, pathToWorkspaceTemplateFileInput); // throw new ShapeChangeAbortException(); // } // // copy template to outputFile // try { // FileUtils.copyFile(workspaceTemplateFileInput, outputFile); // } catch (IOException e) { // result.addFatalError(this, 8, e.getMessage()); // e.printStackTrace(System.err); // throw new ShapeChangeAbortException(); // } // connect to EA repository in outputFile absolutePathOfOutputEAPFile = outputFile.getAbsolutePath(); rep = new Repository(); if (!rep.OpenFile(absolutePathOfOutputEAPFile)) { String errormsg = rep.GetLastError(); r.addError(null, 30, errormsg, outputFilename); rep = null; throw new ShapeChangeAbortException(); } // get template packages rep.RefreshModelView(0); Collection<Package> c = rep.GetModels(); Package root = c.GetAt((short) 0); Collection<Package> modelPkgs = root.GetPackages(); if (modelPkgs.GetCount() == 0 || !modelPkgs.GetAt((short) 0).GetStereotypeEx().equalsIgnoreCase("ArcGIS")) { result.addError(this, 9); throw new ShapeChangeAbortException(); } else { Package workspacePkg = modelPkgs.GetAt((short) 0); this.workspacePkgId = workspacePkg.GetPackageID(); // eaPkgByModelPkg.put(appSchemaPkg, workspacePkg); } Integer features = EAModelUtil.getEAChildPackageByName(rep, workspacePkgId, TEMPLATE_PKG_FEATURES_NAME); if (features == null) { result.addError(this, 102, TEMPLATE_PKG_FEATURES_NAME); throw new ShapeChangeAbortException(); } else { this.featuresPkgId = features; this.eaPkgIdByModelPkg_byWorkspaceSubPkgId.put(featuresPkgId, new HashMap<PackageInfo, Integer>()); } Integer domains = EAModelUtil.getEAChildPackageByName(rep, workspacePkgId, TEMPLATE_PKG_DOMAINS_NAME); if (domains == null) { result.addError(this, 102, TEMPLATE_PKG_DOMAINS_NAME); throw new ShapeChangeAbortException(); } else { this.domainsPkgId = domains; this.eaPkgIdByModelPkg_byWorkspaceSubPkgId.put(domainsPkgId, new HashMap<PackageInfo, Integer>()); } Integer tables = EAModelUtil.getEAChildPackageByName(rep, workspacePkgId, TEMPLATE_PKG_TABLES_NAME); if (tables == null) { result.addError(this, 102, TEMPLATE_PKG_TABLES_NAME); throw new ShapeChangeAbortException(); } else { this.tablesPkgId = tables; this.eaPkgIdByModelPkg_byWorkspaceSubPkgId.put(tablesPkgId, new HashMap<PackageInfo, Integer>()); } Integer assocClasses = EAModelUtil.getEAChildPackageByName(rep, workspacePkgId, TEMPLATE_PKG_ASSOCIATION_CLASSES_NAME); if (assocClasses == null) { result.addError(this, 102, TEMPLATE_PKG_ASSOCIATION_CLASSES_NAME); throw new ShapeChangeAbortException(); } else { this.assocClassesPkgId = assocClasses; this.eaPkgIdByModelPkg_byWorkspaceSubPkgId.put(assocClassesPkgId, new HashMap<PackageInfo, Integer>()); } ProcessConfiguration pc = o.getCurrentProcessConfig(); // parse map entries List<ProcessMapEntry> mapEntries = pc.getMapEntries(); Map<String, ProcessMapEntry> mes = new HashMap<String, ProcessMapEntry>(); for (ProcessMapEntry pme : mapEntries) { // TODO ignores value of 'rule' attribute in map entry, so if there // were map entries for different rules with same 'type' attribute // value, this needs to be updated if (pme.hasTargetType()) { mes.put(pme.getType(), pme); } else { result.addError(this, 11, pme.getType()); } } this.processMapEntries = mes; // initialize set with esri types suited for numeric range constraints esriTypesSuitedForRangeConstraint.add("esriFieldTypeInteger"); esriTypesSuitedForRangeConstraint.add("esriFieldTypeDouble"); // parse numeric range delta parameter String numRangeDeltaParamValue = options.parameter(this.getClass().getName(), PARAM_VALUE_RANGE_DELTA); if (numRangeDeltaParamValue != null) { try { double delta = Double.parseDouble(numRangeDeltaParamValue); this.numRangeDelta = delta; } catch (NumberFormatException e) { result.addError(this, 12); } } // change the default documentation template? documentationTemplate = options.parameter(this.getClass().getName(), PARAM_DOCUMENTATION_TEMPLATE); documentationNoValue = options.parameter(this.getClass().getName(), PARAM_DOCUMENTATION_NOVALUE); }
From source file:com.silverpeas.templatedesigner.control.TemplateDesignerSessionController.java
private void removeLayer(File file) throws PublicationTemplateException { try {/*from w ww. j a v a2 s. c om*/ FileUtils.forceDelete(file); } catch (IOException ioe) { throw new PublicationTemplateException("PublicationTemplateImpl.removeLayer()", "form.EX_ERR_CANT_REMOVE_LAYER", "Publication Template FileName : " + file.getAbsolutePath(), ioe); } }
From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.TestConsoleRSAKeyPairGenerator.java
@Test public void testCheckAndPromptToOverwriteFile02() throws IOException { File file = new File("testCheckAndPromptToOverwriteFile02"); FileUtils.writeStringToFile(file, "test string"); try {/* w w w . j a va 2 s . c om*/ EasyMock.expect(this.device.readLine("The file \"%s\" already exists. Overwrite it (YES/no)? ", file.getCanonicalPath())).andReturn("y"); EasyMock.replay(this.generator, this.device); assertTrue("The value returned should be true.", this.console.checkAndPromptToOverwriteFile("testCheckAndPromptToOverwriteFile02")); } finally { FileUtils.forceDelete(file); } }
From source file:hoot.services.controllers.ingest.FileUploadResourceTest.java
@Test @Category(UnitTest.class) public void TestCreateNativeRequestOgr() throws Exception { String input = "TransportationGroundCrv.shp"; String jobId = "test-id-123"; String wkdirpath = homeFolder + "/upload/" + jobId; File workingDir = new File(wkdirpath); FileUtils.forceMkdir(workingDir);/*from w w w . j ava 2 s. c om*/ org.junit.Assert.assertTrue(workingDir.exists()); File srcFile = new File(homeFolder + "/test-files/service/FileUploadResourceTest/" + input); File destFile = new File(wkdirpath + "/" + input); FileUtils.copyFile(srcFile, destFile); org.junit.Assert.assertTrue(destFile.exists()); FileUploadResource res = new FileUploadResource(); // Shape 1 JSONArray results = new JSONArray(); JSONObject zipStat = new JSONObject(); List<String> inputsList = new ArrayList<String>(); inputsList.add(input); res._buildNativeRequest(jobId, "TransportationGroundCrv", "shp", input, results, zipStat); int shpCnt = 0; int osmCnt = 0; int fgdbCnt = 0; int zipCnt = 0; int shpZipCnt = 0; int osmZipCnt = 0; int fgdbZipCnt = 0; List<String> zipList = new ArrayList<String>(); shpCnt += (Integer) zipStat.get("shpcnt"); fgdbCnt += (Integer) zipStat.get("fgdbcnt"); osmCnt += (Integer) zipStat.get("osmcnt"); // shape 2 // shape input = "TransportationGroundCrv2.shp"; srcFile = new File(homeFolder + "/test-files/service/FileUploadResourceTest/TransportationGroundCrv.shp"); destFile = new File(wkdirpath + "/" + input); FileUtils.copyFile(srcFile, destFile); org.junit.Assert.assertTrue(destFile.exists()); inputsList.add(input); res._buildNativeRequest(jobId, "TransportationGroundCrv2", "shp", input, results, zipStat); shpCnt += (Integer) zipStat.get("shpcnt"); fgdbCnt += (Integer) zipStat.get("fgdbcnt"); osmCnt += (Integer) zipStat.get("osmcnt"); JSONArray resA = res._createNativeRequest(results, zipCnt, shpZipCnt, fgdbZipCnt, osmZipCnt, shpCnt, fgdbCnt, osmCnt, zipList, "TDSv61.js", jobId, "ogr", inputsList); JSONObject req = (JSONObject) resA.get(0); JSONArray params = (JSONArray) req.get("params"); int nP = 0; for (Object o : params) { JSONObject oJ = (JSONObject) o; if (oJ.get("INPUT") != null) { org.junit.Assert.assertTrue(oJ.get("INPUT").toString() .equals("\"TransportationGroundCrv.shp\" \"TransportationGroundCrv2.shp\" ")); nP++; } if (oJ.get("INPUT_PATH") != null) { org.junit.Assert.assertTrue(oJ.get("INPUT_PATH").toString().equals("upload/test-id-123")); nP++; } if (oJ.get("INPUT_TYPE") != null) { org.junit.Assert.assertTrue(oJ.get("INPUT_TYPE").toString().equals("OGR")); nP++; } } org.junit.Assert.assertTrue(nP == 3); FileUtils.forceDelete(workingDir); }