List of usage examples for java.nio.file Path toString
String toString();
From source file:com.github.ffremont.microservices.springboot.node.tasks.InstallJarTaskTest.java
@Test public void testRun() throws Exception { MicroServiceTask msTask = this.create(); MicroServiceRest ms = msTask.getMs(); Path msVersionFolder = Paths.get(this.nodeBase, ms.getName(), ms.getVersion()); 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 w w w .jav a2 s . c o m Path checksumFile = Paths.get(msVersionFolder.toString(), InstallTask.CHECKSUM_FILE_NAME + ".txt"); assertTrue(Files.exists(checksumFile)); assertArrayEquals(ms.getSha1().getBytes(), Files.readAllBytes(checksumFile)); Path binary = Paths.get(msVersionFolder.toString(), NodeHelper.jarNameOf(ms)); assertTrue(Files.exists(binary)); LOG.info("testRun : " + nodeBase); }
From source file:org.wte4j.ui.server.services.TemplateServiceIntegrationTest.java
@Test public void listUniqueContendIds() throws URISyntaxException { Path filePath = Paths.get(getClass().getResource("template.docx").toURI()); List<String> contentIds = templateService.listUniqueContentIds(filePath.toString()); assertEquals(1, contentIds.size());// ww w .j a v a 2 s .c o m assertEquals("template", contentIds.get(0)); }
From source file:com.controller.rest.FileREST.java
/** * AP?/* w ww . ja v a 2s. c om*/ * * @param session * @param req * @param ataType * @return * @throws java.lang.Exception */ @RequestMapping(value = "/file/isAPTempFileExists", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") public String isAPTempFileExists(HttpSession session, HttpServletRequest req, @RequestParam("ataType") String ataType) throws Exception { JsonObject jsonObj = new JsonObject(); //? UserHeader LOGININFO = ((UserHeader) session.getAttribute("LoginInfo")); AtaType AtaTypeEnum; //?AtaType euum try { AtaTypeEnum = AtaType.valueOf(ataType); } catch (Exception e) { throw new MyException(""); } try { //AP Path tempPath = new CreateFilePath().GetAPTempPath( req.getSession().getServletContext().getRealPath("/resources/temp"), LOGININFO, AtaTypeEnum, "", ""); //? File books = new File(tempPath.toString()); if (books.listFiles().length == 0) { throw new MyException("?"); } jsonObj.addProperty("success", "OK"); } catch (Exception e) { throw e; } return jsonObj.toString(); }
From source file:com.thoughtworks.go.server.service.plugins.AnalyticsPluginAssetsServiceTest.java
@Test public void onPluginMetadataLoad_shouldCachePluginStaticAssets() throws Exception { railsRoot = temporaryFolder.newFolder(); Path pluginDirPath = Paths.get(railsRoot.getAbsolutePath(), "public", "assets", "plugins", PLUGIN_ID); Path dirtyPath = Paths.get(pluginDirPath.toString(), "dirty.txt"); FileUtils.forceMkdirParent(dirtyPath.toFile()); Files.write(dirtyPath, "hello".getBytes()); assertTrue(pluginDirPath.toFile().exists()); assertTrue(dirtyPath.toFile().exists()); addAnalyticsPluginInfoToStore(PLUGIN_ID); when(servletContext.getInitParameter("rails.root")).thenReturn("rails-root"); when(servletContext.getRealPath("rails-root")).thenReturn(railsRoot.getAbsolutePath()); when(extension.canHandlePlugin(PLUGIN_ID)).thenReturn(true); when(extension.getStaticAssets(PLUGIN_ID)).thenReturn(testDataZipArchive()); assetsService.onPluginMetadataCreate(PLUGIN_ID); assertFalse(dirtyPath.toFile().exists()); assertTrue(pluginDirPath.toFile().exists()); assertTrue(/*from w w w. ja v a2 s .c om*/ Paths.get(railsRoot.getAbsolutePath(), "public", assetsService.assetPathFor(PLUGIN_ID), "test.txt") .toFile().exists()); }
From source file:com.bekwam.resignator.commands.UnsignCommand.java
public void unsignJAR(Path sourceJARFile, Path targetJARFile, Consumer<String> observer) throws CommandExecutionException { if (logger.isDebugEnabled()) { logger.debug("[UNSIGN] sourceJARFilePath={}, targetJARFilePath={}", sourceJARFile, targetJARFile); }//from w ww . j a v a 2s . c o m // // Verify source jar // File sourceJarFile = verifySource(sourceJARFile); observer.accept("Verifying source JAR '" + sourceJarFile.getName() + "'"); if (logger.isDebugEnabled()) { logger.debug("[UNSIGN] source jar file name={}", sourceJarFile.getName()); } // // Create a temporary and unique folder // observer.accept("Creating temp dir"); Path appDir = createTempDir(); Preconditions.checkNotNull(tempDir); // // Register cleanup handler // observer.accept("Registering cleanup handler"); registerCleanup(); // // Copy jarFile to temp folder // observer.accept("Copying JAR '" + sourceJarFile.getName() + "'"); Path workingJarFile = copyJAR(sourceJarFile); // // Unpack JAR // unJAR(workingJarFile.toString(), tempDir); observer.accept("Unpacking JAR '" + workingJarFile.toString() + "'"); observer.accept("Deleting working JAR file"); workingJarFile.toFile().delete(); // don't include for later re-jar operation // // Locate .SF files. Remove these and corresponding signature blocks like .RSA. // observer.accept("Removing old signature blocks"); File metaInfDir = new File(tempDir.toFile(), "META-INF"); removeSigs(metaInfDir); // // Strip the SHA.*\: entries from the MANIFEST.MF (ok to leave Name: lines?) // observer.accept("Editing MANIFEST.MF"); editManifest(metaInfDir); // // Repack JAR // observer.accept("Repacking JAR '" + targetJARFile.toString() + "'"); repackJAR(targetJARFile, appDir); }
From source file:com.thesmartweb.swebrank.Diffbot.java
/** * Method to the token of diffbot/* w w w .j a v a 2 s. co m*/ * @param config_path the configuration path to get the diffbot key * @return the token in a string */ public String GetToken(String config_path) { Path input_path = Paths.get(config_path); DataManipulation getfiles = new DataManipulation();//class responsible for the extraction of paths Collection<File> inputs_files;//array to include the paths of the txt files inputs_files = getfiles.getinputfiles(input_path.toString(), "txt");//method to retrieve all the path of the input documents List<String> tokenList = new ArrayList<>(); ReadInput ri = new ReadInput(); for (File input : inputs_files) { if (input.getName().contains("diffbottoken")) { tokenList = ri.readLinesConfig(input); } } if (tokenList.size() > 0) { return tokenList.get(0); } else { String output = ""; return output; } }
From source file:fr.duminy.jbackup.core.task.BackupTaskTest.java
private BackupConfiguration toBackupConfiguration(ArchiveFactory mockFactory, ArchiveParameters archiveParameters) { final BackupConfiguration config = new BackupConfiguration(); config.setName("testBackupTask"); config.setRelativeEntries(archiveParameters.isRelativeEntries()); final Path archiveDirectory2 = archiveParameters.getArchive().getParent().toAbsolutePath(); config.setTargetDirectory(archiveDirectory2.toString()); for (ArchiveParameters.Source source : archiveParameters.getSources()) { String dirFilter = toJexlExpression(source.getDirFilter()); String fileFilter = toJexlExpression(source.getFileFilter()); final Path sourcePath = source.getSource().toAbsolutePath(); config.addSource(sourcePath, dirFilter, fileFilter); }//from w w w. ja va 2 s. c o m config.setArchiveFactory(mockFactory); return config; }
From source file:company.gonapps.loghut.dao.TagDao.java
public List<String> getTagNames() throws IOException { List<String> names = new LinkedList<>(); Pattern pattern = Pattern.compile("/([^/]+)$"); rrwl.readLock().lock();/* ww w . j ava2 s. com*/ try (DirectoryStream<Path> ds = Files .newDirectoryStream(Paths.get(settingDao.getSetting("tags.directory")))) { for (Path path : ds) { Matcher matcher = pattern.matcher(path.toString()); if (matcher.find() && Files.isDirectory(path)) names.add(matcher.group(1)); } } finally { rrwl.readLock().unlock(); } return names; }
From source file:fr.ortolang.diffusion.usecase.StoreAndRetrieveFileUseCase.java
@Test public void testHostSimpleFile() throws URISyntaxException { // Path origin = Paths.get(HostAndRetrieveFileTest.class.getClassLoader().getResource("file1.jpg").getPath()); Path origin = Paths.get("/home/jerome/Images/test.jpg"); LOGGER.log(Level.INFO, "Origin file to insert in container : " + origin.toString()); Path destination = Paths.get("/tmp/" + System.currentTimeMillis()); LOGGER.log(Level.INFO,/*from w w w . j a v a2 s . c o m*/ "Destination file for retrieving content from container : " + destination.toString()); String wkey = UUID.randomUUID().toString(); String okey = UUID.randomUUID().toString(); // Create a Workspace try { core.createWorkspace(wkey, "Test Workspace", "test"); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); fail(e.getMessage()); } // Create the Digital Object try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Files.copy(origin, baos); //core.createDataObject(wkey, "/" + okey, "Test Object", "A really simple test object !!", baos.toByteArray()); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); fail(e.getMessage()); } // Check that the object is registered in the browser try { OrtolangObjectIdentifier identifier = browser.lookup(okey); assertEquals(identifier.getService(), CoreService.SERVICE_NAME); assertEquals(identifier.getType(), DataObject.OBJECT_TYPE); } catch (BrowserServiceException | KeyNotFoundException | AccessDeniedException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); fail(e.getMessage()); } // Retrieve this digital object informations using the key try { DataObject object = core.readDataObject(okey); LOGGER.log(Level.INFO, "Detected mime type : " + object.getMimeType()); LOGGER.log(Level.INFO, "Detected size : " + object.getSize()); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); fail(e.getMessage()); } // Retrieve this digital object data using the key try { //byte[] data = core.readDataObjectContent(okey); //Files.copy(new ByteArrayInputStream(data), destination); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); fail(e.getMessage()); } // Compare origin and destination : try { InputStream input1 = Files.newInputStream(origin); InputStream input2 = Files.newInputStream(destination); assertTrue(IOUtils.contentEquals(input1, input2)); input1.close(); input2.close(); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); fail(e.getMessage()); } // Delete destination try { Files.delete(destination); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } }
From source file:com.github.ffremont.microservices.springboot.node.tasks.InstallTaskTest.java
@Test(expected = InvalidInstallationException.class) public void testRunDetectChecksumKo() throws Exception { MicroServiceTask msTask = this.create(); doNothing().when(mockInstallJarTask).run(anyObject()); doNothing().when(mockInstallPropertiesTask).run(anyObject()); Path msVersionFolder = Paths.get(this.nodeBase, msTask.getMs().getName(), msTask.getMs().getVersion()); ;// ww w . j ava2 s.co m Files.createDirectories(msVersionFolder); when(helper.targetDirOf(anyObject())).thenReturn(msVersionFolder); Path checksumPath = Paths.get(msVersionFolder.toString(), InstallTask.CHECKSUM_FILE_NAME + ".txt"); Files.write(checksumPath, "FAILLLL SHA1".getBytes()); task.run(msTask); verify(mockInstallJarTask, times(1)).run(anyObject()); verify(mockInstallPropertiesTask, times(0)).run(anyObject()); }