List of usage examples for java.nio.file Path resolve
default Path resolve(String other)
From source file:com.goldmansachs.kata2go.tools.utils.TarGz.java
public static void decompress(InputStream tarGzInputStream, Path outDir) throws IOException { GzipCompressorInputStream gzipStream = new GzipCompressorInputStream(tarGzInputStream); TarArchiveInputStream tarInput = new TarArchiveInputStream(gzipStream); TarArchiveEntry entry;// ww w . j a va2 s . co m int bufferSize = 1024; while ((entry = (TarArchiveEntry) tarInput.getNextEntry()) != null) { String entryName = entry.getName(); // strip out the leading directory like the --strip tar argument String entryNameWithoutLeadingDir = entryName.substring(entryName.indexOf("/") + 1); if (entryNameWithoutLeadingDir.isEmpty()) { continue; } Path outFile = outDir.resolve(entryNameWithoutLeadingDir); if (entry.isDirectory()) { outFile.toFile().mkdirs(); continue; } int count; byte data[] = new byte[bufferSize]; BufferedOutputStream fios = new BufferedOutputStream(new FileOutputStream(outFile.toFile()), bufferSize); while ((count = tarInput.read(data, 0, bufferSize)) != -1) { fios.write(data, 0, count); } fios.close(); } tarInput.close(); gzipStream.close(); }
From source file:ec.edu.chyc.manejopersonal.util.ServerUtils.java
/** * Mueve los archivos subidos de acuerdo al nombre del archivo que ha tenido antes y ahora. Si son diferentes, * entonces se mueve el anterior y se lo trata como "eliminado", posteriormente si el nombre del archivo nuevo * existe, se mueve del temporal al directorio destino. Si los dos nombres de archivos son iguales, no se realiza ninguna accin. * @param nombreArchivoAntiguo Nombre del archivo antiguo ya almacenado y que se debe encontrar en pathDestino, * se lo tratar como eliminado (llevar el prefijo 'eliminado_' si este nombre es diferente al nombreArchivoNuevo. * @param nombreArchivoNuevo Nombre del archivo nuevo que se encuentra en el Path Temporal. Si el nombre no est vaco, * se mover el archivo del directorio temporal al pathDestino. * @param pathDestino Ruta destino donde se almacenar el nombreArchivoNuevo. * @throws IOException En caso de que no se pueda mover ya sea el archivo antiguo o el archivo nuevo. *//*ww w.j a v a 2 s . com*/ public static void procesarAntiguoNuevoArchivo(String nombreArchivoAntiguo, String nombreArchivoNuevo, Path pathDestino) throws IOException { //si no se ha cambiado el nombre del archivo, es porque el archivo subido no se ha modificado boolean archivoSeMantiene = false; if (!nombreArchivoAntiguo.isEmpty() && nombreArchivoAntiguo.equals(nombreArchivoNuevo)) { archivoSeMantiene = true; } if (!nombreArchivoAntiguo.isEmpty() && !archivoSeMantiene) { //en caso de que existi un archivo almacenado anteriormente, se elimina, pero solo en caso de que se haya modificado el archivo original Path pathArchivoAntiguo = pathDestino.resolve(nombreArchivoAntiguo).normalize(); if (Files.exists(pathArchivoAntiguo) && Files.isRegularFile(pathArchivoAntiguo)) { Path pathNuevoDestino = ServerUtils.getPathTemp().resolve("eliminado_" + nombreArchivoAntiguo); Files.move(pathArchivoAntiguo, pathNuevoDestino, REPLACE_EXISTING); } } if (!nombreArchivoNuevo.isEmpty() && !archivoSeMantiene) { //si se subi el nuevo archivo, copiar del directorio de temporales al original de destino, despus eliminar el archivo temporal // solo realizarlo si se modific el archivo original Path origen = ServerUtils.getPathTemp().resolve(nombreArchivoNuevo); Path destino = pathDestino.resolve(nombreArchivoNuevo).normalize(); //FileUtils.copyFile(origen, destino); Files.move(origen, destino, REPLACE_EXISTING); } }
From source file:com.cloudbees.clickstack.util.Files2.java
@Nonnull public static Path copyArtifactToDirectory(@Nonnull Path sourceDir, @Nonnull String artifactId, @Nonnull Path dest) throws RuntimeIOException { Path source = findArtifact(sourceDir, artifactId); try {//from www. ja v a 2s . c om return Files.copy(source, dest.resolve(source.getFileName())); } catch (IOException e) { throw new RuntimeIOException("Exception copying " + source.getFileName() + " to " + sourceDir, e); } }
From source file:org.n52.io.request.IoParameters.java
private static InputStream getDefaultConfigFile() { try {//from ww w .j av a 2s .c om Path path = Paths.get(IoParameters.class.getResource("/").toURI()); File config = path.resolve(DEFAULT_CONFIG_FILE).toFile(); return config.exists() ? new FileInputStream(config) : IoParameters.class.getClassLoader().getResourceAsStream("/" + DEFAULT_CONFIG_FILE); } catch (URISyntaxException | IOException e) { LOGGER.debug("Could not find default config under '{}'", DEFAULT_CONFIG_FILE, e); return null; } }
From source file:com.amazonaws.codepipeline.jenkinsplugin.CompressionTools.java
public static Path resolveWorkspacePath(final File workspace, final String outputPath) throws FileNotFoundException { Path path = null; if (workspace != null) { if (!outputPath.contains(workspace.getAbsolutePath())) { path = Paths.get(workspace.getAbsolutePath(), outputPath); } else {//from w w w . j ava 2 s .c om path = Paths.get(outputPath); } } else { final String attemptPath; final URL tmp = CompressionTools.class.getClassLoader().getResource(""); if (tmp != null) { attemptPath = tmp.getPath(); } else { attemptPath = ""; } if (attemptPath != null) { path = Paths.get(attemptPath); } } if (path == null) { throw new FileNotFoundException("Could not resolve path for " + outputPath); } path.resolve(outputPath); return path; }
From source file:de.teamgrit.grit.preprocess.fetch.SvnFetcher.java
/** * Updates the directory path for remote svn repos. * * @param location//from w w w. j a v a2 s. c om * the adress of the repo * @param oldPath * the current path * @return an updated path */ private static Path updateDirectoryPath(String location, Path oldPath) { Path targetDirectory = Paths.get(oldPath.toAbsolutePath().toString()); // check whether the svn repo is given via a url or is given via a path if (!location.startsWith("file://")) { // We need to get the name of the checked out folder / repo. int occurences = StringUtils.countMatches(location, "/"); int index = StringUtils.ordinalIndexOf(location, "/", occurences); String temp = location.substring(index + 1); // stitch the last part of the hyperlink to the targetDirectory to // receive the structure targetDirectory = Paths.get(targetDirectory.toString(), temp); } else { targetDirectory = targetDirectory.resolve(Paths.get(location).getFileName()); } return targetDirectory; }
From source file:com.github.anba.es6draft.util.Resources.java
/** * Loads the named resource through {@link Class#getResourceAsStream(String)} if the uri starts with "resource:", * otherwise loads the resource with {@link Files#newInputStream(Path, java.nio.file.OpenOption...)}. */// ww w .j a v a 2 s . c o m public static InputStream resource(String uri, Path basedir) throws IOException { final String RESOURCE = "resource:"; if (uri.startsWith(RESOURCE)) { String name = uri.substring(RESOURCE.length()); InputStream res = Resources.class.getResourceAsStream(name); if (res == null) { throw new IOException("resource not found: " + name); } return res; } else { return Files.newInputStream(basedir.resolve(Paths.get(uri))); } }
From source file:org.bonitasoft.web.designer.repository.JsonFileBasedPersister.java
public Path jsonFile(Path directory, String id) { return directory.resolve(id + ".json"); }
From source file:fi.jumi.launcher.daemon.DirBasedSteward.java
@Override public Path getDaemonJar(Path jumiHome) { Path extractedJar = jumiHome.resolve("lib/" + daemonJar.getDaemonJarName()); createIfDoesNotExist(extractedJar);/*from w w w . j a v a 2 s . c o m*/ return extractedJar; }
From source file:org.wte4j.examples.showcase.server.hsql.ShowCaseDbInitializer.java
void createDateBaseFiles(Path dataBaseLocation, boolean overide) { Path hsqlScript = dataBaseLocation.resolve("wte4j-showcase.script"); if (overide || !Files.exists(hsqlScript)) { try {//from w ww . java 2 s. com if (!Files.exists(dataBaseLocation)) { Files.createDirectories(dataBaseLocation); } Resource[] resources = resourceLoader.getResources("classpath:/db/*"); for (Resource resource : resources) { Path filePath = dataBaseLocation.resolve(resource.getFilename()); File source = resource.getFile(); Files.copy(source.toPath(), filePath, StandardCopyOption.REPLACE_EXISTING); } } catch (IOException e) { throw new IllegalArgumentException("can not copy database files", e); } } }