List of usage examples for java.nio.file Path toString
String toString();
From source file:alliance.docs.DocumentationTest.java
@Test public void testBrokenAnchorsPresent() throws IOException, URISyntaxException { List<Path> docs = Files.list(getPath()).filter(f -> f.toString().endsWith(HTML_DIRECTORY)) .collect(Collectors.toList()); Set<String> links = new HashSet<>(); Set<String> anchors = new HashSet<>(); for (Path path : docs) { Document doc = Jsoup.parse(path.toFile(), "UTF-8", EMPTY_STRING); String thisDoc = StringUtils.substringAfterLast(path.toString(), File.separator); Elements elements = doc.body().getAllElements(); for (Element element : elements) { if (!element.toString().contains(":") && StringUtils.substringBetween(element.toString(), HREF_ANCHOR, CLOSE) != null) { links.add(thisDoc + "#" + StringUtils.substringBetween(element.toString(), HREF_ANCHOR, CLOSE)); }/* w w w . j a v a2s. c o m*/ anchors.add(thisDoc + "#" + StringUtils.substringBetween(element.toString(), ID, CLOSE)); } } links.removeAll(anchors); assertThat("Anchors missing section reference: " + links.toString(), links.isEmpty()); }
From source file:com.cirrus.server.osgi.service.local.LocalStorageService.java
@Override public CirrusFolderData createDirectory(final String path) throws ServiceRequestFailedException { final Path newPath = Paths.get(this.getGlobalContext().getRootPath(), path); if (Files.exists(newPath)) { throw new ServiceRequestFailedException("The directory <" + newPath + "> already exists"); } else {//from w ww . ja v a 2s .c o m try { final Path directories = Files.createDirectories(newPath); return new CirrusFolderData(directories.toString()); } catch (final IOException e) { throw new ServiceRequestFailedException(e); } } }
From source file:org.eclipse.vorto.remoterepository.internal.dao.FilesystemModelDAO.java
private ModelContent getModelContent(Path file) { ModelType modelType = getModelType(file.toString()); try {/*ww w . j a va 2 s .co m*/ return new ModelContent(modelType, Files.readAllBytes(file)); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCDirectoryPathDAO.java
/** * Delete a current workspace directory. * If the given Path does not lead to a current workspace directory, the workspace will * remain unchanged./* ww w . j av a 2 s . c o m*/ * * @param directory must be a valid path to an existing directory * @throws DAOException if operation fails */ @Override public void delete(Path directory) throws DAOException { LOGGER.debug("Deleting directory {}", directory); try { String pathString = directory.toString(); jdbcTemplate.update(DELETE_STATEMENT, pathString); } catch (DataAccessException ex) { throw new DAOException("Failed to delete delete directory", ex); } }
From source file:com.hpe.caf.worker.testing.preparation.PreparationResultProcessor.java
protected Path saveContentFile(TestItem<TInput, TExpected> testItem, String baseFileName, String extension, InputStream dataStream) throws IOException { String outputFolder = getOutputFolder(); if (configuration.isStoreTestCaseWithInput()) { Path path = Paths.get(testItem.getInputData().getInputFile()).getParent(); outputFolder = Paths.get(configuration.getTestDataFolder(), path == null ? "" : path.toString()) .toString();//from ww w .jav a 2s .com } baseFileName = FilenameUtils.normalize(baseFileName); baseFileName = Paths.get(baseFileName).getFileName().toString(); Path contentFile = Paths.get(outputFolder, baseFileName + "." + extension + ".content"); Files.deleteIfExists(contentFile); Files.copy(dataStream, contentFile, REPLACE_EXISTING); return getRelativeLocation(contentFile); }
From source file:com.c4om.autoconf.ulysses.configanalyzer.configurationextractor.LocalCopyConfigurationsExtractor.java
/** * This method performs the extraction. * The context must contain: //from w w w . j a va2s .c o m * <ul> * <li>One or more {@link ConfigureAppsTarget} returned by {@link ConfigurationAnalysisContext#getInputTargets()}. * All the referenced {@link Application} must return "file://" URIs at {@link Application#getConfigurationURIs()}.</li> * <li>An {@link Environment} object returned by {@link ConfigurationAnalysisContext#getInputEnvironment()}, from which * the configuration of the runtime where all the referenced applications are run.</li> * </ul> * @see com.c4om.autoconf.ulysses.interfaces.configanalyzer.configurationextractor.ConfigurationsExtractor#extractConfigurations(com.c4om.autoconf.ulysses.interfaces.configanalyzer.core.datastructures.ConfigurationAnalysisContext) */ @Override public void extractConfigurations(ConfigurationAnalysisContext context) throws ConfigurationExtractionException { try { Path tempFolderPath = Files.createTempDirectory("ConfigurationAnalyzer"); for (Target currentTarget : context.getInputTargets().values()) { if (!(currentTarget instanceof ConfigureAppsTarget)) { continue; } Properties configurationAnalyzerSettings = context.getConfigurationAnalyzerSettings(); String runtimeConfigurationDirName = configurationAnalyzerSettings .getProperty(PROPERTY_KEY_RUNTIME_CONFIGURATION_FILENAME); if (runtimeConfigurationDirName == null) { throw new ConfigurationExtractionException( "Property '" + PROPERTY_KEY_RUNTIME_CONFIGURATION_FILENAME + "' not found"); } ConfigureAppsTarget currentConfigureAppsTarget = (ConfigureAppsTarget) currentTarget; for (String appId : currentConfigureAppsTarget.getParameters().keySet()) { Path subfolderForApp = tempFolderPath.resolve(Paths.get(appId)); List<File> copiedFiles = new ArrayList<>(); Files.createDirectory(subfolderForApp); //We copy the application configuration files to the root of the directory. //We also copy the runtime configuration. Application currentApplication = (Application) currentConfigureAppsTarget.getParameters() .get(appId); for (URI configurationURI : currentApplication.getConfigurationURIs()) { //TODO: Let other configuration URIs live, specially, SVN-based ones, which should be extracted by other extractors. This would require some refactoring. if (!configurationURI.getScheme().equalsIgnoreCase("file")) { throw new ConfigurationExtractionException( "URI '" + configurationURI.toString() + "' does not have a 'file' scheme"); } Path configurationPath = Paths.get(configurationURI); Path configurationPathName = configurationPath.getFileName(); if (configurationPathName.toString().equals(runtimeConfigurationDirName)) { throw new ConfigurationExtractionException( "One of the application configuration files has the same name than the runtime configuration folder ('" + runtimeConfigurationDirName + "')"); } Path destinationConfigurationPath = Files.copy(configurationPath, subfolderForApp.resolve(configurationPathName), REPLACE_EXISTING); File destinationConfigurationFile = destinationConfigurationPath.toFile(); copiedFiles.add(destinationConfigurationFile); } File runtimeConfigurationDirectory = new File( context.getInputEnvironment().getApplicationConfigurations().get(appId)); File destinationRuntimeConfigurationDirectory = subfolderForApp .resolve(runtimeConfigurationDirName).toFile(); FileUtils.copyDirectory(runtimeConfigurationDirectory, destinationRuntimeConfigurationDirectory); copiedFiles.add(destinationRuntimeConfigurationDirectory); ExtractedConfiguration<File> extractedConfiguration = new FileExtractedConfiguration(appId, currentTarget, copiedFiles); context.getExtractedConfigurations().add(extractedConfiguration); } } } catch (IOException e) { throw new ConfigurationExtractionException(e); } }
From source file:com.cirrus.server.osgi.service.local.LocalStorageService.java
private ICirrusData createCirrusDataFromFile(final Path path) throws IOException { if (Files.isDirectory(path)) { return new CirrusFolderData(path.toString()); } else {// ww w. ja v a 2s.co m return new CirrusFileData(path.toString(), Files.size(path)); } }
From source file:net.mymam.fileprocessor.VideoFileGenerator.java
private Path generateFile(String cmdLineTemplate, Path in, Path outDir, String outFile, int maxWidth, int maxHeight) throws FileProcessingFailedException { try {/*from w ww. j ava2 s. c o m*/ Path out = Paths.get(outDir.toString(), outFile); // TODO: Make sure that weired file names cannot be used to inject shell scripts, like '"; rm -r *;' String cmdLine = cmdLineTemplate.replace("$INPUT_FILE", "\"" + in.toString() + "\"") .replace("$OUTPUT_FILE", "\"" + out.toString() + "\"") .replace("$MAX_WIDTH", Integer.toString(maxWidth)) .replace("$MAX_HEIGHT", Integer.toString(maxHeight)); CommandLine cmd = CommandLine.parse(cmdLine); System.out.println("Executing " + cmd); // TODO: Use logging. new DefaultExecutor().execute(cmd); return out; } catch (Throwable t) { throw new FileProcessingFailedException(t); } }
From source file:joachimeichborn.geotag.io.writer.kml.KmzWriter.java
public void write(final Track aTrack, final Path aOutputFile) throws IOException { final String documentTitle = FilenameUtils.removeExtension(aOutputFile.getFileName().toString()); final GeoTagKml kml = createKml(documentTitle, aTrack); kml.marshalAsKmz(aOutputFile.toString()); logger.fine("Wrote track to " + aOutputFile); }
From source file:org.devgateway.toolkit.forms.service.DerbyDatabaseBackupService.java
/** * Gets the URL (directory/file) of the backupPath. Adds as prefixes the * last leaf of backup's location parent directory + {@link #databaseName} * If the backupPath does not have a parent, it uses the host name from * {@link InetAddress#getLocalHost()}// w ww .j a va2s. c o m * * @param backupPath * the parent directory for the backup * @return the backup url to be used by the backup procedure * @throws UnknownHostException */ private String createBackupURL(final String backupPath) { java.text.SimpleDateFormat todaysDate = new java.text.SimpleDateFormat("yyyyMMdd-HHmmss"); String parent = null; Path originalPath = Paths.get(backupPath); Path filePath = originalPath.getFileName(); if (filePath != null) { parent = filePath.toString(); } else { try { // fall back to hostname instead parent = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOGGER.debug("Cannot get localhost/hostname! " + e); return null; } } String backupURL = backupPath + "/" + parent + "-" + databaseName + "-" + todaysDate.format((java.util.Calendar.getInstance()).getTime()); return backupURL; }