List of usage examples for java.nio.file Path toString
String toString();
From source file:org.wte4j.ui.server.services.TemplateServiceIntegrationTest.java
@Test public void saveInvalidTemplateData() throws URISyntaxException, IOException { Template<TemplateDto> template = createAndPersistTestTemplate(); TemplateDto dto = new TemplateDto(); dto.setDocumentName(template.getDocumentName()); dto.setLanguage(template.getLanguage()); Path filePath = Paths.get(getClass().getResource("template.docx").toURI()); try {/* w ww . j av a 2s . com*/ templateService.saveTemplateData(dto, filePath.toString()); fail("Exeption expected"); } catch (InvalidTemplateServiceException e) { assertEquals(1, e.getDetails().size()); String detail = e.getDetails().get(0); assertTrue(detail.startsWith("template")); } }
From source file:com.spectralogic.ds3client.helpers.FileObjectGetter_Test.java
@Test public void testThatNamedPipeThrows() throws IOException, InterruptedException { Assume.assumeFalse(Platform.isWindows()); final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String FIFO_NAME = "bFifo"; final AtomicBoolean caughtException = new AtomicBoolean(false); try {//w w w.j a v a 2 s .c om Runtime.getRuntime().exec("mkfifo " + Paths.get(tempDirectory.toString(), FIFO_NAME)).waitFor(); new FileObjectGetter(tempDirectory).buildChannel(FIFO_NAME); } catch (final UnrecoverableIOException e) { assertTrue(e.getMessage().contains(FIFO_NAME)); caughtException.set(true); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } assertTrue(caughtException.get()); }
From source file:ffx.potential.utils.PotentialsFileOpener.java
public PotentialsFileOpener(Path filepath) { this(filepath.toString()); }
From source file:org.wte4j.ui.server.services.TemplateServiceIntegrationTest.java
@Test public void createInvalidTemplateFromFile() throws URISyntaxException { TemplateDto template = new TemplateDto(); template.setDocumentName("test"); template.setLanguage("en"); template.setInputType(TemplateDto.class.getName()); Path filePath = Paths.get(getClass().getResource("template.docx").toURI()); try {// ww w. j av a 2 s.c o m templateService.createTemplate(template, filePath.toString()); fail(); } catch (InvalidTemplateServiceException e) { assertEquals(1, e.getDetails().size()); String detail = e.getDetails().get(0); assertTrue(detail.startsWith("template")); } }
From source file:com.github.ffremont.microservices.springboot.node.tasks.InstallJarTaskTest.java
@Test(expected = InvalidInstallationException.class) public void testRunKoChecksum() throws Exception { MicroServiceRest ms = new MicroServiceRest(); ms.setId("007"); ms.setName("msClient"); ms.setVersion("1.0.0"); ms.setSha1("FAILLL"); MicroServiceTask msTask = new MicroServiceTask(ms, Paths.get(Thread.currentThread().getContextClassLoader().getResource("hello.jar").toURI())); Path msVersionFolder = Paths.get(this.nodeBase, ms.getName(), ms.getVersion()); ;//w ww . ja v a 2 s . co m Files.createDirectories(msVersionFolder); when(helper.targetDirOf(anyObject())).thenReturn(msVersionFolder); when(helper.targetJarOf(anyObject())) .thenReturn(Paths.get(msVersionFolder.toString(), NodeHelper.jarNameOf(ms))); task.run(msTask); }
From source file:au.org.ands.vocabs.toolkit.provider.importer.SesameImporterProvider.java
/** Upload the RDF data into the Sesame repository. * @param taskInfo The TaskInfo object describing the entire task. * @param subtask The details of the subtask * @param results HashMap representing the result of the task. * @return True, iff the upload succeeded. */// w w w .java 2s .c o m public final boolean uploadRDF(final TaskInfo taskInfo, final JsonNode subtask, final HashMap<String, String> results) { RepositoryManager manager = null; try { manager = RepositoryProvider.getRepositoryManager(sesameServer); String repositoryID = ToolkitFileUtils.getSesameRepositoryId(taskInfo); Repository repository = manager.getRepository(repositoryID); if (repository == null) { // Repository is missing. This is bad. logger.error("Sesame uploadRDF, repository missing"); return false; } RepositoryConnection con = null; try { con = repository.getConnection(); // If required, remove all existing triples if (subtask.get("clear") != null && subtask.get("clear").booleanValue()) { con.clear(); } Path dir = Paths.get(ToolkitFileUtils.getTaskHarvestOutputPath(taskInfo)); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path entry : stream) { File file = new File(entry.toString()); logger.debug("Full path:" + entry.toAbsolutePath().toString()); con.add(file, "", Rio.getParserFormatForFileName(entry.toString())); } } catch (DirectoryIteratorException | IOException ex) { // I/O error encountered during the iteration, // the cause is an IOException results.put(TaskStatus.EXCEPTION, "Exception in Sesame uploadRDF"); logger.error("Exception in Sesame uploadRDF:", ex); return false; } } catch (RDFParseException e) { results.put(TaskStatus.EXCEPTION, "Exception in Sesame uploadRDF"); logger.error("Sesame uploadRDF, error parsing RDF: ", e); return false; } finally { if (con != null) { con.close(); } } return true; } catch (RepositoryConfigException | RepositoryException e) { results.put(TaskStatus.EXCEPTION, "Exception in Sesame uploadRDF"); logger.error("Exception in Sesame uploadRDF()", e); } return false; }
From source file:com.bekwam.resignator.SettingsController.java
private boolean validateJDKHome(String jdkHome) { Preconditions.checkNotNull(jdkHome); Map<Path, Integer> cmdsAndResults = new LinkedHashMap<>(); cmdsAndResults.put(Paths.get(jdkHome, "bin", "keytool"), 0); cmdsAndResults.put(Paths.get(jdkHome, "bin", "jarsigner"), 0); cmdsAndResults.put(Paths.get(jdkHome, "bin", "jar"), 1); try {/*from w ww. j a v a2 s. c o m*/ piSettings.setVisible(true); piSettings.setProgress(0.0d); for (Path cmd : cmdsAndResults.keySet()) { if (logger.isDebugEnabled()) { logger.debug("[VAL JDKHOME] cmd={}", cmd.toString()); } Process p = Runtime.getRuntime().exec(new String[] { cmd.toString() }); int exitValue = p.waitFor(); if (logger.isDebugEnabled()) { logger.debug("[VAL JDKHOME] retval={}", exitValue); } if (exitValue != cmdsAndResults.get(cmd)) { // lookup expected return code return false; } piSettings.setProgress(piSettings.getProgress() + 1 / cmdsAndResults.size()); } } catch (IOException | InterruptedException exc) { logger.error("error running '{" + jdkHome + "}'", exc); return false; } finally { piSettings.setVisible(false); piSettings.setProgress(0.0d); } return true; }
From source file:com.cognifide.qa.bb.config.YamlConfig.java
private Map<? extends String, ? extends Map<String, String>> getContextsFromYaml(Path path) { TypeReference<Map<String, Map<String, String>>> typeRef = new TypeReference<Map<String, Map<String, String>>>() { };//from www. j a v a2 s.c o m return YamlReader.read(ADDITIONAL_CONTEXTS_FOLDER + StringUtils.substringAfter(path.toString(), ADDITIONAL_CONTEXTS_FOLDER_NAME), typeRef); }
From source file:company.gonapps.loghut.dao.TagDao.java
public List<String> getYears(String tagName) throws IOException { List<String> years = new LinkedList<>(); rrwl.readLock().lock();//from ww w . j a v a2 s . c o m try (DirectoryStream<Path> ds = Files .newDirectoryStream(Paths.get(settingDao.getSetting("tags.directory") + "/" + tagName))) { for (Path path : ds) { Matcher matcher = tagYearPattern.matcher(path.toString()); if (matcher.find() && Files.isDirectory(path)) years.add(matcher.group(1)); } } finally { rrwl.readLock().unlock(); } Collections.sort(years, new YearComparator()); return years; }
From source file:company.gonapps.loghut.dao.TagDao.java
public List<String> getMonths(String tagName, int year) throws IOException { List<String> months = new LinkedList<>(); rrwl.readLock().lock();/*from w w w. j av a 2 s . c o m*/ try (DirectoryStream<Path> ds = Files.newDirectoryStream(Paths.get( settingDao.getSetting("tags.directory") + "/" + tagName + "/" + String.format("%04d", year)))) { for (Path path : ds) { Matcher matcher = tagMonthPattern.matcher(path.toString()); if (matcher.find() && path.toFile().isDirectory()) months.add(matcher.group(1)); } } rrwl.readLock().unlock(); Collections.sort(months, new MonthComparator()); return months; }