List of usage examples for java.nio.file Files delete
public static void delete(Path path) throws IOException
From source file:org.wso2.appserver.ApplicationServerConfigurationTest.java
@Test(description = "Loads the XML file content of a valid WSO2 App Server specific server level configuration " + "descriptor", priority = 2) public void testObjectLoadingFromDescriptor() throws IOException, ApplicationServerConfigurationException { // deletes the existing server descriptor Files.delete(dist_server_descriptor); Path source = Paths.get(TestConstants.TEST_RESOURCES, Constants.APP_SERVER_DESCRIPTOR); Files.copy(source, dist_server_descriptor); lifecycle_components.stream().forEach(component -> loader .lifecycleEvent(new LifecycleEvent(component, Lifecycle.BEFORE_START_EVENT, null))); ApplicationServerConfiguration actual = ServerConfigurationLoader.getServerConfiguration(); ApplicationServerConfiguration expected = generateDefault(); Assert.assertTrue(compare(actual, expected)); // deletes the existing server descriptor Files.delete(dist_server_descriptor); }
From source file:es.ucm.fdi.storage.business.entity.StorageObject.java
public void delete() throws IOException { String folder = internalName.substring(0, 2); Files.delete(root.resolve(folder).resolve(internalName)); }
From source file:at.ac.tuwien.infosys.ArtifactBuilderTest.java
@After public void tearDown() { try { Files.delete(mockedPath); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.github.ffremont.microservices.springboot.node.NodeEngine.java
public void update() { LOG.debug("Mise jour du node \"{}\"", node); // rcup des ms du node List<MicroServiceRest> lesMs = msService.getMicroServices(); PsCommand.PsCommandResult psResult = (new PsCommand()).exec(); MicroServiceTask msTask;/*from ww w. ja va2s. c om*/ for (MicroServiceRest ms : lesMs) { try { msTask = new MicroServiceTask(ms); if (MsEtatRest.INACTIF.equals(ms.getMsEtat()) && psResult.isRunning(ms.getId())) { try { shutdownTask.run(msTask); } catch (FailStopedException fe) { LOG.warn("Arrt du micro service impossible", fe); } } // version courante - NOT RUNNING ? if (MsEtatRest.ACTIF.equals(ms.getMsEtat()) && !psResult.isRunning(ms.getIdVersion())) { // ancienne version running ? if (psResult.isRunning(ms.getId())) { try { shutdownTask.run(msTask); } catch (FailStopedException fe) { LOG.warn("Arrt du micro service impossible", fe); } } try { startTask.run(msTask); } catch (FileMsNotFoundException ex) { LOG.warn("Dmarrage du micro service impossible : " + ms.getId(), ex); try { unInstallTask.run(msTask); } catch (InvalidInstallationException e) { LOG.warn("Dsinstallation impossible", e); } msTask.setJar(msService.getBinary(ms.getName())); try { LOG.info("Tentative d'installation du microservice {}", ms.getId()); installTask.run(msTask); } finally { if (msTask.getJar() != null) { try { Files.delete(msTask.getJar()); } catch (IOException ex1) { LOG.warn("Suppression du binaire temporaire impossible", ex1); } } } } } } catch (TaskException ex) { LOG.error("Mise jour du micro service impossible : " + ms.getId(), ex); } } }
From source file:org.silverpeas.core.io.file.SilverpeasFile.java
/** * @see java.io.File#delete()// w w w.j av a 2 s. co m * <p> * A chain of post-processors will be ran once this file deleted to perform possible additional * treatments. * @return true if the deletion succeed, false otherwise. */ @Override public boolean delete() { boolean deleted = false; if (exists()) { try { Files.delete(toPath()); deleted = true; } catch (IOException e) { SilverLogger.getLogger(this).silent(e); } SilverpeasFileProvider.processAfter(this, SilverpeasFileProcessor.ProcessingContext.DELETION); } return deleted; }
From source file:com.fujitsu.dc.core.model.file.StreamingOutputForDavFile.java
@Override public void write(OutputStream output) throws IOException, WebApplicationException { if (null == hardLinkInput) { throw new WebApplicationException(new BinaryDataNotFoundException(hardLinkPath.toString())); }// w ww . j av a 2 s . c o m try { IOUtils.copy(hardLinkInput, output); } finally { IOUtils.closeQuietly(hardLinkInput); // ????? Files.delete(hardLinkPath); } }
From source file:org.crosswalk.eclipse.cdt.helpers.ExportHelper.java
public static int generateDebPackage(IProject project, DebPackageParameters packageparameters) throws IOException { int runResult = 0; StringBuilder cmd = new StringBuilder(); final Map<String, String> env = new HashMap<String, String>(System.getenv()); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); Path sourceManifestFile = FileSystems.getDefault().getPath(project.getLocation().toString(), "manifest.json"); //copy the manifest.json file String manifestLocation = project.getLocation().toString() + File.separator + "manifest.json"; JSONObject manifest = new JSONObject(new JSONTokener( //get the manifest file new FileReader(manifestLocation))); String packageName = CdtConstants.CROSSWALK_PACKAGE_PREFIX + manifest.get("name"); ProjectHelper projectHelper = new ProjectHelper(); projectHelper.resourceHandler(root.getLocation().toString()); String sourceFolder = project.getLocation().toString(); String targetFolder = sourceFolder + File.separator + ".tmp" + File.separator + packageName + File.separator + "app"; Path targetManifestFile = FileSystems.getDefault().getPath(targetFolder, "manifest.json"); Files.copy(sourceManifestFile, targetManifestFile, REPLACE_EXISTING); //copy the icon file if (NewProjectWizardState.useDefaultIcon) { //do nothing,since we copied the icon from org.crosswalk.appName folder } else { //user-specified icon.We have to delete the default icons and copy the user-specified icon String iconName = manifest.getJSONArray("icons").getJSONObject(2).get("src").toString(); Path sourceIconFile = FileSystems.getDefault().getPath(sourceFolder, iconName); Path targetIconFile = FileSystems.getDefault().getPath(targetFolder, iconName); Path defaultIconFile1 = FileSystems.getDefault().getPath(targetFolder, "icon-48.png"); Path defaultIconFile2 = FileSystems.getDefault().getPath(targetFolder, "icon.png"); Files.copy(sourceIconFile, targetIconFile, REPLACE_EXISTING); Files.delete(defaultIconFile1); Files.delete(defaultIconFile2); }/*from ww w . java 2 s . c om*/ //copy the launch file. //We must copy this file no matter whether the name is index.html since user may change it after setting it in manifestSettingPage if (NewProjectWizardState.isPackagedProject) { String startUrl = manifest.get("start_url").toString(); Path sourceStartUrlFile = FileSystems.getDefault().getPath(sourceFolder, startUrl); Path targetStartUrlFile = FileSystems.getDefault().getPath(targetFolder, startUrl); Files.copy(sourceStartUrlFile, targetStartUrlFile, REPLACE_EXISTING); } File buildDir = new File( project.getLocation().toString() + File.separator + ".tmp" + File.separator + packageName); cmd.append("crosswalk-app build"); pMonitor.worked(1); Process process = Runtime.getRuntime().exec(cmd.toString(), mapToStringArray(env), buildDir);//execute cmd in specific targetFolder try { process.waitFor(); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //copy the deb package to user-specified path String debPackageName = packageparameters.appName + "_" + packageparameters.appVersion + "-1_" + packageparameters.supportedArch + ".deb"; Path source = FileSystems.getDefault().getPath(buildDir.toString(), "pkg", debPackageName); Path target = FileSystems.getDefault().getPath(packageparameters.targetFolder, debPackageName); Files.copy(source, target, REPLACE_EXISTING); try { for (int i = 0; i < 20; i++) { pMonitor.worked(1); Thread.sleep(10); } } catch (InterruptedException e) { } // redirect the error and input stream try { exportStream(process.getErrorStream(), System.err); exportStream(process.getInputStream(), System.out); } catch (Exception e) { e.printStackTrace(); } try { runResult = process.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); CdtPluginLog.logError("Error when involking package tool.", e); } return runResult; }
From source file:org.fim.internal.hash.FileHasherPerformanceTest.java
private Path createFileWithSize(int fileCount, int fileSize) throws IOException { Path newFile = context.getRepositoryRootDir().resolve("file_" + fileCount); if (Files.exists(newFile)) { Files.delete(newFile); }/*from w w w . j a v a 2 s . c o m*/ if (fileSize == 0) { Files.createFile(newFile); return newFile; } try (ByteArrayOutputStream out = new ByteArrayOutputStream(fileSize)) { int contentSize = _1_KB / 4; int remaining = fileSize; for (; remaining > 0; globalSequenceCount++) { int size = min(contentSize, remaining); byte[] content = generateContent(globalSequenceCount, size); remaining -= size; out.write(content); } byte[] fileContent = out.toByteArray(); assertThat(fileContent.length).isEqualTo(fileSize); Files.write(newFile, fileContent, CREATE); } return newFile; }
From source file:cc.kave.commons.externalserializationtests.ExternalTestCaseProviderTest.java
@Test public void settingsFileShouldBeOptional() throws IOException, ClassNotFoundException { Files.delete(settingsFile); TestCase firstTestCase = getFirstTestCase(); assertEquals(Object.class, firstTestCase.serializedType); }
From source file:act.installer.pubchem.PubchemTTLMergerTest.java
@After public void tearDown() throws Exception { // Clean up temp dir once the test is complete. TODO: use mocks instead maybe? But testing RocksDB helps too... /* With help from:/* w w w.j av a 2 s .c o m*/ * http://stackoverflow.com/questions/779519/delete-directories-recursively-in-java/27917071#27917071 */ Files.walkFileTree(tempDirPath, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { // walkFileTree may ignore . and .., but I have never found it a /bad/ idea to check for these special names. if (!THIS_DIR.equals(file.toFile().getName()) && !PARENT_DIR.equals(file.toFile().getName())) { Files.delete(file); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { throw exc; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); // One last check to make sure the top level directory is removed. if (tempDirPath.toFile().exists()) { Files.delete(tempDirPath); } }