List of usage examples for java.nio.file Path getParent
Path getParent();
From source file:ch.ledcom.jpreseed.web.TemporaryPreseedStoreTest.java
@Test public void preseedsAreDeletedAfterOnClose() throws IOException { Path preseed; try (TemporaryPreseedStore preseedStore = new TemporaryPreseedStore()) { preseedStore.addPreseeds(singleton(testPreseed)); ImmutableSet<Path> preseeds = preseedStore.getPreseeds(); preseed = preseeds.iterator().next(); }/* w w w . ja v a 2 s. c o m*/ assertThat(preseed).doesNotExist(); assertThat(preseed.getParent()).doesNotExist(); }
From source file:com.tc.config.DefaultConfigurationProvider.java
protected TcConfiguration getTcConfiguration(Path configurationPath, ClassLoader serviceClassLoader) throws Exception { return TCConfigurationParser.parse(Files.newInputStream(configurationPath), new ArrayList<>(), configurationPath.getParent().toString(), serviceClassLoader); }
From source file:org.ow2.proactive.scheduler.examples.FTPConnector.java
private void makeRemoteDirectoriesIfNotExist(FTPClient ftpClient, Path path) throws IOException { if (path.getParent() == null) { createRemoteDirectoryIfNotExists(ftpClient, path.toString()); } else {//from w ww.j ava2s . co m makeRemoteDirectoriesIfNotExist(ftpClient, path.getParent()); createRemoteDirectoryIfNotExists(ftpClient, path.getFileName().toString()); } }
From source file:it.infn.ct.futuregateway.apiserver.storage.LocalStorage.java
@Override public final void storeFile(final RESOURCE res, final String id, final InputStream input, final String destinationName, final String operation) throws IOException { Path filePath; if (operation != null && !operation.isEmpty()) { filePath = Paths.get(path, res.name().toLowerCase(), id, operation, destinationName); } else {/*w ww.j a v a 2s. c o m*/ filePath = Paths.get(path, res.name().toLowerCase(), id, destinationName); } Files.createDirectories(filePath.getParent()); Files.deleteIfExists(filePath); Files.copy(input, filePath); log.debug("File " + destinationName + " written at '" + filePath + "'"); }
From source file:org.canova.image.recordreader.BaseImageRecordReader.java
@Override public void initialize(InputSplit split) throws IOException { inputSplit = split;/*from w ww . ja v a 2 s .c o m*/ if (split instanceof FileSplit) { URI[] locations = split.locations(); if (locations != null && locations.length >= 1) { if (locations.length > 1) { List<File> allFiles = new ArrayList<>(); for (URI location : locations) { File imgFile = new File(location); if (!imgFile.isDirectory() && containsFormat(imgFile.getAbsolutePath())) allFiles.add(imgFile); if (appendLabel) { File parentDir = imgFile.getParentFile(); String name = parentDir.getName(); if (!labels.contains(name)) labels.add(name); if (pattern != null) { String label = name.split(pattern)[patternPosition]; fileNameMap.put(imgFile.toString(), label); } } } iter = allFiles.listIterator(); } else { File curr = new File(locations[0]); if (!curr.exists()) throw new IllegalArgumentException("Path " + curr.getAbsolutePath() + " does not exist!"); if (curr.isDirectory()) iter = FileUtils.iterateFiles(curr, null, true); else iter = Collections.singletonList(curr).listIterator(); } } //remove the root directory FileSplit split1 = (FileSplit) split; labels.remove(split1.getRootDir()); } else if (split instanceof InputStreamInputSplit) { InputStreamInputSplit split2 = (InputStreamInputSplit) split; InputStream is = split2.getIs(); URI[] locations = split2.locations(); INDArray load = imageLoader.asRowVector(is); record = RecordConverter.toRecord(load); for (int i = 0; i < load.length(); i++) { if (appendLabel) { Path path = Paths.get(locations[0]); String parent = path.getParent().toString(); //could have been a uri if (parent.contains("/")) { parent = parent.substring(parent.lastIndexOf('/') + 1); } int label = labels.indexOf(parent); if (label >= 0) record.add(new DoubleWritable(labels.indexOf(parent))); else throw new IllegalStateException("Illegal label " + parent); } } is.close(); } }
From source file:com.github.ferstl.depgraph.AbstractGraphMojo.java
private void writeDotFile(String dotGraph) throws IOException { Path outputFilePath = this.outputFile.toPath(); Path parent = outputFilePath.getParent(); if (parent != null) { Files.createDirectories(parent); }//from w ww. j av a 2 s. co m try (Writer writer = Files.newBufferedWriter(outputFilePath, StandardCharsets.UTF_8)) { writer.write(dotGraph); } }
From source file:org.basinmc.maven.plugins.bsdiff.DiffMojo.java
/** * Retrieves a remote artifact and stores it in a pre-defined cache directory. *//*from ww w.ja va 2 s . com*/ @Nonnull private Path retrieveSourceFile() throws MojoFailureException { HttpClient client = HttpClients.createMinimal(); String fileName; { String path = this.sourceURL.getPath(); int i = path.lastIndexOf('/'); fileName = path.substring(i + 1); } try { this.getLog().info("Downloading source artifact from " + this.sourceURL.toExternalForm()); HttpGet request = new HttpGet(this.sourceURL.toURI()); HttpResponse response = client.execute(request); if (response.containsHeader("Content-Disposition")) { String disposition = response.getLastHeader("Content-Disposition").getValue(); Matcher matcher = DISPOSITION_PATTERN.matcher(disposition); if (matcher.matches()) { fileName = URLDecoder.decode(matcher.group(1), "UTF-8"); } } this.getLog().info("Storing " + fileName + " in cache directory"); Path outputPath = this.cacheDirectory.toPath().resolve(fileName); if (!Files.isDirectory(outputPath.getParent())) { Files.createDirectories(outputPath.getParent()); } try (InputStream inputStream = response.getEntity().getContent()) { try (ReadableByteChannel inputChannel = Channels.newChannel(inputStream)) { try (FileChannel outputChannel = FileChannel.open(outputPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { outputChannel.transferFrom(inputChannel, 0, Long.MAX_VALUE); } } } return outputPath; } catch (IOException ex) { throw new MojoFailureException("Failed to read/write source artifact: " + ex.getMessage(), ex); } catch (URISyntaxException ex) { throw new MojoFailureException("Invalid source URI: " + ex.getMessage(), ex); } }
From source file:codes.writeonce.maven.plugins.soy.CompileMojo.java
private void generateJs(List<Path> soyFiles, List<Path> xliffFiles, byte[] sourceDigestBytes) throws IOException, NoSuchAlgorithmException { final Path outputRootPath = jsOutputDirectory.toPath(); FileUtils.deleteDirectory(jsOutputDirectory); Files.createDirectories(outputRootPath); FileUtils.deleteDirectory(javaOutputDirectory); final Path javaSourceOutputPath = getJavaSourceOutputPath(); Files.createDirectories(javaSourceOutputPath); final SoyFileSet soyFileSet = getSoyFileSet(soyFiles); if (xliffFiles.isEmpty()) { getLog().info("No translations detected. Using default messages."); generateJs(soyFiles, soyFileSet, null, outputRootPath); } else {/* ww w . j av a 2 s.c om*/ final SoyMsgBundleHandler smbh = new SoyMsgBundleHandler(new XliffMsgPlugin()); for (final Path xliffFilePath : xliffFiles) { final SoyMsgBundle smb = smbh.createFromFile(translations.toPath().resolve(xliffFilePath).toFile()); final Path outputPath = Utils.removeSuffix(outputRootPath.resolve(xliffFilePath), XLIFF_EXTENSION); generateJs(soyFiles, soyFileSet, smb, outputPath); } } final ImmutableMap<String, String> parseInfo = SoyFileSetAccessor.generateParseInfo(soyFileSet, javaPackage, javaClassNameSource.getValue()); final Charset classSourceCharset; if (StringUtils.isEmpty(javaOutputCharsetName)) { classSourceCharset = Charset.defaultCharset(); getLog().warn("Using platform encoding (" + classSourceCharset.displayName() + " actually) to generate SOY sources, i.e. build is platform dependent!"); } else { classSourceCharset = Charset.forName(javaOutputCharsetName); } for (final Map.Entry<String, String> entry : parseInfo.entrySet()) { final String classFileName = entry.getKey(); final String classSource = entry.getValue(); try (FileOutputStream out = new FileOutputStream(javaSourceOutputPath.resolve(classFileName).toFile()); OutputStreamWriter writer = new OutputStreamWriter(out, classSourceCharset)) { writer.write(classSource); } } final byte[] targetDigestBytes = getGeneratedFilesDigest(); final Path statusFilePath = getStatusFilePath(); Files.createDirectories(statusFilePath.getParent()); try (FileOutputStream out = new FileOutputStream(statusFilePath.toFile()); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(out, TEXT_DIGEST_CHARSET); BufferedWriter writer = new BufferedWriter(outputStreamWriter)) { writer.write(Hex.encodeHex(sourceDigestBytes)); writer.newLine(); writer.write(Hex.encodeHex(targetDigestBytes)); writer.newLine(); } }
From source file:dk.dma.msinm.web.OsmStaticMap.java
/** * Main GET method/*from w ww . j a v a 2 s .co m*/ * * @param request servlet request * @param response servlet response */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { // Sanity checks if (StringUtils.isBlank(request.getParameter("zoom")) || StringUtils.isBlank(request.getParameter("center")) || StringUtils.isBlank(request.getParameter("size"))) { throw new IllegalArgumentException("Must provide zoom, size and center parameters"); } MapImageCtx ctx = new MapImageCtx(); parseParams(ctx, request); if (useMapCache) { // use map cache, so check cache for map if (!checkMapCache(ctx)) { // map is not in cache, needs to be build BufferedImage image = makeMap(ctx); Path path = repositoryService.getRepoRoot().resolve(mapCacheIDToFilename(ctx)); Files.createDirectories(path.getParent()); ImageIO.write(image, "png", path.toFile()); // And write to response sendHeader(response); ImageIO.write(image, "png", response.getOutputStream()); } else { // map is in cache sendHeader(response); Path path = repositoryService.getRepoRoot().resolve(mapCacheIDToFilename(ctx)); response.setContentLength((int) path.toFile().length()); FileInputStream fileInputStream = new FileInputStream(path.toFile()); OutputStream responseOutputStream = response.getOutputStream(); int bytes; while ((bytes = fileInputStream.read()) != -1) { responseOutputStream.write(bytes); } } } else { // no cache, make map, send headers and deliver png BufferedImage image = makeMap(ctx); sendHeader(response); ImageIO.write(image, "png", response.getOutputStream()); } }
From source file:io.specto.hoverfly.junit.core.Hoverfly.java
private void persistSimulation(Path path, Simulation simulation) throws IOException { Files.createDirectories(path.getParent()); JSON_PRETTY_PRINTER.writeValue(path.toFile(), simulation); }