List of usage examples for java.nio.file Path toString
String toString();
From source file:ru.xxlabaza.popa.template.TemplaterFreemarker.java
@Override protected void write(Path templatePath, Map<String, Object> mappings, Writer writer) throws Exception { Template template = freemarkerConfiguration.getTemplate(templatePath.toString()); template.process(mappings, writer);//from w w w .ja va 2s . c o m }
From source file:com.github.ffremont.microservices.springboot.node.tasks.InstallJarTask.java
@Override public void run(MicroServiceTask task) throws TaskException { Path msVersionFolder = helper.targetDirOf(task.getMs()); Path checksumPath = Paths.get(msVersionFolder.toString(), InstallTask.CHECKSUM_FILE_NAME + ".txt"); Path jarTarget = helper.targetJarOf(task.getMs()); try {/*ww w .j a va 2s . c om*/ if (task.getJar() == null) { throw new InvalidInstallationException("Jar indisponible dans l'objet MicroServiceTask"); } Files.copy(task.getJar(), jarTarget); MessageDigest md = MessageDigest.getInstance("SHA-1"); try (DigestInputStream digestIs = new DigestInputStream(new FileInputStream(jarTarget.toFile()), md)) { byte[] buffer = new byte[10240]; // 10ko while (0 < digestIs.read(buffer)) { } digestIs.close(); } byte[] checksumTarget = md.digest(); if (!String.format("%032X", new BigInteger(1, checksumTarget)) .equals(task.getMs().getSha1().toUpperCase())) { throw new InvalidInstallationException( "Le checksum n'est pas valide suite la copie : " + this.nodeBase); } Files.write(checksumPath, task.getMs().getSha1().getBytes()); LOG.debug("Cration du fichier checksum.txt"); } catch (IOException | NoSuchAlgorithmException ex) { throw new InvalidInstallationException("Impossible d'installer le jar", ex); } }
From source file:com.bc.fiduceo.ingest.IngestionToolTest.java
@Test public void testGetMatcher() { final Path path = mock(Path.class); final Path fileName = mock(Path.class); when(fileName.toString()).thenReturn("2345.nc"); when(path.getFileName()).thenReturn(fileName); Pattern pattern = Pattern.compile("[0-9]{4}.nc"); Matcher matcher = IngestionTool.getMatcher(path, pattern); assertTrue(matcher.matches());/*from w w w. j a v a 2 s . c o m*/ pattern = Pattern.compile("\\d.nc"); matcher = IngestionTool.getMatcher(path, pattern); assertFalse(matcher.matches()); }
From source file:com.yahoo.maven.visitor.SuccessfulCompilationAsserter.java
public void assertNoCompilationErrors() throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, StandardCharsets.UTF_8)) { List<File> javaFiles = new ArrayList<>(); try (Stream<Path> stream = Files.walk(scratchSpace)) { Iterator<Path> iterator = stream.iterator(); while (iterator.hasNext()) { Path path = iterator.next(); if (Files.isRegularFile(path) && "java".equals(FilenameUtils.getExtension(path.toString()))) { javaFiles.add(path.toFile()); }/* w w w. j a va 2 s . c om*/ } } Iterable<? extends JavaFileObject> compilationUnits = fileManager .getJavaFileObjectsFromFiles(javaFiles); compiler.getTask(null, fileManager, diagnostics, Arrays.asList("-classpath", System.getProperty("java.class.path")), null, compilationUnits) .call(); } int errors = 0; for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) { if (Diagnostic.Kind.ERROR.equals(diagnostic.getKind())) { System.err.println(diagnostic); errors++; } } assertEquals(0, errors); }
From source file:com.github.tomakehurst.wiremock.common.SingleRootFileSourceTest.java
@Test public void writesTextFileEvenWhenRootIsARelativePath() throws IOException { String relativeRootPath = "./target/tmp/"; FileUtils.forceMkdir(new File(relativeRootPath)); SingleRootFileSource fileSource = new SingleRootFileSource(relativeRootPath); Path fileAbsolutePath = Paths.get(relativeRootPath).toAbsolutePath().resolve("myFile"); fileSource.writeTextFile(fileAbsolutePath.toString(), "stuff"); assertThat(Files.exists(fileAbsolutePath), is(true)); }
From source file:org.bonitasoft.web.designer.workspace.WorkspacePathResolverTest.java
@Test public void should_resolve_workspace_path_by_getting_system_property() throws Exception { Path expectedWorkspacePath = Paths.get("someUserDefinedDirectory"); when(env.getProperty(WORKSPACE_KEY)).thenReturn(expectedWorkspacePath.toString()); assertThat(workspacePathResolver.getWorkspacePath()).isEqualTo(expectedWorkspacePath); }
From source file:mx.eersya.beans.CreateItemBean.java
public void savePicture() { try {/* ww w. java 2 s . c om*/ Path path = Paths.get("/home/eersya/Projects/W/"); String filename = FilenameUtils.getBaseName(picture.getFileName()); String extension = FilenameUtils.getExtension(picture.getFileName()); Path file = Files.createTempFile(path, filename, "." + extension); picturePath = file.toString(); try (InputStream in = picture.getInputstream()) { Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING); } catch (IOException exa) { System.err.println(exa); } picturePath = file.toString(); System.out.println("Picture:" + picturePath); } catch (IOException ex) { System.err.println(ex); } }
From source file:org.trustedanalytics.uploader.UploaderConfigurationLocal.java
@Bean public InFolderObjectStore inFolderObjectStore() { Path path = Paths.get(System.getProperty("user.dir"), "target", "uploads"); path.toFile().mkdirs();//from ww w. j a v a 2 s .c om return new InFolderObjectStore(path.toString()); }
From source file:cn.edu.zjnu.acm.judge.controller.CKFinderController.java
@Nullable @ToDownload/*from ww w .j av a2 s . co m*/ @GetMapping("/support/ckfinder") public Path ckfinder(@RequestParam("path") String path) { log.info(path); try { int indexOf = path.indexOf('?'); Path parent = judgeConfiguration.getUploadDirectory(); Path imagePath = parent.getFileSystem() .getPath(parent.toString(), indexOf > 0 ? path.substring(0, indexOf) : path).normalize(); if (!imagePath.startsWith(parent)) { log.debug("absolute path parent='{}' path='{}'", parent, imagePath); return null; } return imagePath; } catch (IllegalArgumentException ex) { return null; } }
From source file:com.teradata.benchto.driver.loader.QueryLoader.java
/** * Loads query from given {@link Path}// ww w.j a v a 2 s.co m * * @param queryName - path to SQL query file * @return {@link Query} with the SQL query which can be executed on the destination database */ public Query loadFromFile(String queryName) { List<Path> queryPaths = properties.sqlFilesDirs().stream() .map(sqlFilesDir -> sqlFilesDir.resolve(queryName)).filter(Files::isRegularFile).collect(toList()); if (queryPaths.isEmpty()) { throw new BenchmarkExecutionException( format("Could not find any SQL query file for query name: %s", queryName)); } if (queryPaths.size() > 1) { throw new BenchmarkExecutionException( format("Found multiple SQL query files for query name: %s", queryName)); } Path queryPath = getOnlyElement(queryPaths); try { String queryNameWithoutExtension = getNameWithoutExtension(queryPath.toString()); return annotatedQueryParser.parseFile(queryNameWithoutExtension, queryPath); } catch (IOException e) { throw new BenchmarkExecutionException(format("Error during loading query from path %s", queryPath), e); } }