List of usage examples for java.nio.file Path getParent
Path getParent();
From source file:com.googlecode.jmxtrans.model.output.FileWriter.java
public FileWriter(@JsonProperty("typeNames") ImmutableList<String> typeNames, @JsonProperty("booleanAsNumber") boolean booleanAsNumber, @JsonProperty("debug") Boolean debugEnabled, @JsonProperty(PROPERTY_BASEPATH) String filepath, @JsonProperty(PROPERTY_LINE_FORMAT) String lineFormat, @JsonProperty("settings") Map<String, Object> settings) throws IOException { super(typeNames, booleanAsNumber, debugEnabled, settings); this.outputFile = new File(filepath); Path outputFilePath = outputFile.toPath(); this.outputTempFile = new File( outputFilePath.getParent() + File.separator + "." + outputFilePath.getFileName()); if (lineFormat == null) { this.lineFormat = DEFAULT_LINE_FORMAT; } else {/*from w w w . j av a2 s . c om*/ this.lineFormat = lineFormat; } // make sure the permissions allow to manage these files: touch(this.outputFile); touch(this.outputTempFile); }
From source file:com.paolodragone.wsn.WsnConfiguration.java
private Path getFilePath(String filePathString) throws IOException { Path path = Paths.get(filePathString); if (Files.notExists(path)) { Files.createDirectories(path.getParent()); Files.createFile(path);/* w w w.j ava 2 s .c o m*/ } return path; }
From source file:org.sakuli.datamodel.helper.TestCaseStepHelperTest.java
@Test public void testParseSteps() throws Throwable { Path tcFile = getResource("stephelper/tc.js"); FileUtils.writeStringToFile(tcFile.getParent().resolve(TestCaseStepHelper.STEPS_CACHE_FILE).toFile(), "z_step_1\nother_step_2\nstep_3?special\n", Charset.forName("UTF-8")); List<TestCaseStep> steps = TestCaseStepHelper.readCachedStepDefinitions(tcFile); //do this to ensure correct sorting List<TestCaseStep> result = Arrays.asList(steps.get(2), steps.get(0), steps.get(1)); Collections.sort(result);/*w ww. ja va 2s. c o m*/ assertNotNull(getResource(CACHEFILE_NAME)); assertEquals(result.size(), 3); Iterator<TestCaseStep> it = result.iterator(); assertInitStep(it.next(), "z_step_1"); assertInitStep(it.next(), "other_step_2"); assertInitStep(it.next(), "step_3?special"); }
From source file:net.mymam.fileprocessor.VideoFileGenerator.java
private Path makeGeneratedDir(Path origPath) throws FileProcessingFailedException { Path generatedDir = Paths.get(origPath.getParent().toString(), "generated"); try {/*from www . j a v a 2 s . c o m*/ Files.createDirectory(generatedDir); return generatedDir; } catch (FileAlreadyExistsException e) { // ignore return generatedDir; } catch (Throwable t) { throw new FileProcessingFailedException(t); } }
From source file:edu.cornell.mannlib.oce.startup.LogFileAdjuster.java
/** * Confirm that the log file will go into an existing directory, and that * either it does exist, or we can create it. Should also be writeable. */// w ww. j a va2 s. c o m private void validateLogFileSetting(SpecialLog specialLog, String logFile) throws LogAdjustmentException { Path path = Paths.get(logFile); if (!Files.exists(path.getParent())) { throw new LogAdjustmentException("Cannot create " + specialLog + " log file '" + logFile + "', parent directory does not exist."); } if (!Files.exists(path)) { try { Files.createFile(path); } catch (IOException e) { throw new LogAdjustmentException("Failed to create " + specialLog + " log file '" + path + "'", e); } } if (!Files.isWritable(path)) { throw new LogAdjustmentException( "Cannot write to log file '" + logFile + "' for " + specialLog + " log."); } }
From source file:org.osiam.OsiamHome.java
private void copyToHome(Resource resource, Path osiamHomeDir) throws IOException { String pathUnderHome = resource.getURL().toString().replaceFirst(".*home/", ""); Path target = osiamHomeDir.resolve(pathUnderHome); Files.createDirectories(target.getParent()); Files.copy(resource.getInputStream(), target, StandardCopyOption.REPLACE_EXISTING); }
From source file:org.cinchapi.concourse.config.AbstractPreferences.java
/** * Reload the data from the configuration file, in case anything has * changed./* w w w. j a v a 2 s . co m*/ */ protected final void reload() { // Create an empty file if necessary. This means that the subclass can // handle defaults in a seamless manner. Path path = Paths.get(file); if (!Files.exists(path)) { try { if (path.getParent() != null) { Files.createDirectories(path.getParent()); } Files.createFile(path); } catch (IOException e) { throw Throwables.propagate(e); } } handler = ConcourseConfiguration.loadConfig(file); }
From source file:org.niord.web.aton.AtonIconRestService.java
/** * Ensures that parent directories are created * @param file the file whose parent directories will be created *//*www . ja v a 2 s. com*/ private void checkCreateParentDirs(Path file) throws IOException { if (!Files.exists(file.getParent())) { Files.createDirectories(file.getParent()); } }
From source file:fr.duminy.jbackup.core.archive.Decompressor.java
public void decompress(Path archive, Path targetDirectory, TaskListener listener, Cancellable cancellable) throws ArchiveException { if (listener != null) { try {/* w w w . ja v a2 s . c om*/ listener.totalSizeComputed(Files.size(archive)); } catch (IOException ioe) { throw new ArchiveException(ioe); } } targetDirectory = (targetDirectory == null) ? Paths.get(".") : targetDirectory; if (!Files.exists(targetDirectory)) { throw new IllegalArgumentException( String.format("The target directory '%s' doesn't exist.", targetDirectory)); } MutableLong processedSize = new MutableLong(); try (InputStream archiveStream = Files.newInputStream(archive); ArchiveInputStream input = factory.create(archiveStream)) { ArchiveInputStream.Entry entry = getNextEntryIfNotCancelled(input, cancellable); while (entry != null) { InputStream entryStream = createCountingInputStream(listener, processedSize, entry.getInput()); try { Path file = targetDirectory.resolve(entry.getName()); Files.createDirectories(file.getParent()); Files.copy(entryStream, file); } finally { entry.close(); } entry = getNextEntryIfNotCancelled(input, cancellable); } } catch (IOException e) { throw new ArchiveException(e); } catch (Exception e) { throw new ArchiveException(e); } }
From source file:org.gradle.caching.internal.tasks.FileWalkingBenchmark.java
@Benchmark public void java7walk(Blackhole blackhole) { Path path = missing ? missingPath : existingPath; while (!path.equals(tempDirPath)) { path = path.getParent(); blackhole.consume(Files.exists(path)); }// w w w . j a v a 2 s .co m blackhole.consume(path); }