List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:com.github.harti2006.neo4j.StartNeo4jServerMojo.java
private void configureNeo4jServer() throws MojoExecutionException { final Path serverLocation = getServerLocation(); final Path serverPropertiesPath = serverLocation.resolve(Paths.get("conf", "neo4j-server.properties")); final Properties serverProperties = PropertyUtils.loadProperties(serverPropertiesPath.toFile()); serverProperties.setProperty("org.neo4j.server.webserver.port", port); serverProperties.setProperty("org.neo4j.server.webserver.https.enabled", "false"); try {/* ww w. j a v a 2 s .c o m*/ serverProperties.store(newBufferedWriter(serverPropertiesPath, TRUNCATE_EXISTING, WRITE), "Generated by Neo4j Server Maven Plugin"); } catch (IOException e) { throw new MojoExecutionException("Could not configure Neo4j server", e); } }
From source file:com.seleniumtests.driver.DriverExtractor.java
/** * Extract drivers from JAR//from www . j av a 2s.c om * first, check if a driver directory is available in the same directory as the jar * If not, extract * If yes, check version of drivers and compare it to seleniumRobot version * In case of difference, extract * @throws IOException */ public String extractDriver(String driverName) { if (driverName == null) { return null; } String installedDriverVersion = getDriverVersion(driverName); String driverArtifactVersion = PackageUtility.getDriverVersion(); Path driverPath = getDriverPath(driverName); // copy driver only when it was not copied for this driver artifact version if (driverPath.toFile().exists() && (installedDriverVersion == null || !installedDriverVersion.equals(driverArtifactVersion)) || !driverPath.toFile().exists()) { copyDriver(driverName); } // write version file try { FileUtils.writeStringToFile(Paths .get(getDriverPath().toFile().getAbsolutePath(), getDriverVersionFileName(driverName)).toFile(), driverArtifactVersion); } catch (IOException e) { logger.error("driver version not written", e); } return driverPath.toString(); }
From source file:ch.mattrero.foldersync.FoldersSynchronizer.java
boolean syncAdded(final Path sourceItem) { try {//from w w w .j a va 2 s .c o m if (Files.isDirectory(sourceItem)) { FileUtils.copyDirectory(sourceItem.toFile(), resolveBackupItemPath(sourceItem).toFile(), true); logger.debug("Added directory " + sourceItem); } else { Files.copy(sourceItem, resolveBackupItemPath(sourceItem), COPY_ATTRIBUTES, REPLACE_EXISTING); logger.debug("Added file " + sourceItem); } } catch (final IOException e) { logger.warn("Failed to create " + resolveBackupItemPath(sourceItem), e); return false; } return true; }
From source file:cool.pandora.modeller.ui.handlers.iiif.PatchResourceHandler.java
@Override public void execute() { final String message = ApplicationContextUtil.getMessage("bag.message.resourcepatched"); final DefaultBag bag = bagView.getBag(); final List<String> payload = bag.getPayloadPaths(); final Map<String, BagInfoField> map = bag.getInfo().getFieldMap(); final URI resourceContainer = IIIFObjectURI.getResourceContainerURI(map); final String basePath = AbstractBagConstants.DATA_DIRECTORY; final Path rootDir = bagView.getBagRootPath().toPath(); for (final String filePath : payload) { final String filename = BaggerFileEntity.removeBasePath(basePath, filePath); final String destinationURI = getDestinationURI(resourceContainer, filename); final Path absoluteFilePath = rootDir.resolve(filePath); final File resourceFile = absoluteFilePath.toFile(); String formatName = null; Dimension dim = null;// www.ja v a 2 s . c o m InputStream rdfBody = null; final URI uri = URI.create(destinationURI); try { formatName = ImageIOUtil.getImageMIMEType(resourceFile); } catch (final Exception e) { e.printStackTrace(); } try { dim = ImageIOUtil.getImageDimensions(resourceFile); } catch (final Exception e) { e.printStackTrace(); } if (dim != null) { final double imgWidth = dim.getWidth(); final int iw = (int) imgWidth; final double imgHeight = dim.getHeight(); final int ih = (int) imgHeight; try { rdfBody = getResourceMetadata(map, filename, formatName, iw, ih); } catch (final Exception e) { e.printStackTrace(); } } try { ModellerClient.doPatch(uri, rdfBody); ApplicationContextUtil.addConsoleMessage(message + " " + destinationURI); } catch (final ModellerClientFailedException e) { ApplicationContextUtil.addConsoleMessage(getMessage(e)); } } bagView.getControl().invalidate(); }
From source file:com.mweagle.tereus.commands.UpdateCommand.java
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings({ "DM_EXIT", "OBL_UNSATISFIED_OBLIGATION" }) @Override//from w ww. j av a2s.c o m public void run() { Map<String, Object> argumentMap = new HashMap<>(); Optional<OutputStream> osSink = Optional.empty(); int exitCode = 0; final UpdateInput updateInput = new UpdateInput(this.patchDefinitionPath, argumentMap, this.region, this.dryRun); try { if (null != this.outputFilePath) { final Path outputPath = Paths.get(this.outputFilePath); osSink = Optional.of(new FileOutputStream(outputPath.toFile())); } this.update(updateInput, osSink); } catch (Exception ex) { LogManager.getLogger().error(ex); exitCode = 1; } finally { if (osSink.isPresent()) { try { osSink.get().close(); } catch (Exception e) { // NOP } } } System.exit(exitCode); }
From source file:org.bonitasoft.web.designer.studio.workspace.StudioWorkspaceResourceHandler.java
private String createGetURL(final Path filePath, final String action) { String encodedURL;//w ww . ja v a 2 s. c om try { encodedURL = URLEncoder.encode(filePath.toFile().toString(), StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException( "Failed to encode: " + filePath + " with charset: " + StandardCharsets.UTF_8.name(), e); } return restClient.createURI(encodedURL + "/" + action); }
From source file:com.arpnetworking.test.junitbenchmarks.JsonBenchmarkConsumerTest.java
@Test public void testNormalBenchmarkCase() throws IOException { final Path path = Paths.get("target/tmp/test/testConsumer.json"); path.toFile().deleteOnExit(); Files.deleteIfExists(path);/*from w w w . j a v a 2s. c om*/ final JsonBenchmarkConsumer consumer = new JsonBenchmarkConsumer(path); final Result result = DataCreator.createResult(); consumer.accept(result); consumer.close(); // Read the file back in as json final ObjectMapper mapper = ObjectMapperFactory.getInstance(); final JsonNode resultsArray = mapper.readTree(path.toFile()); Assert.assertEquals(1, resultsArray.size()); final JsonNode augmentedResultNode = resultsArray.get(0); Assert.assertTrue(augmentedResultNode.isObject()); final JsonNode resultNode = augmentedResultNode.get("result"); Assert.assertTrue(resultNode.isObject()); Assert.assertEquals("com.arpnetworking.test.junitbenchmarks.JsonBenchmarkConsumerTest", resultNode.get("testClassName").asText()); Assert.assertEquals("testNormalBenchmarkCase", resultNode.get("testMethodName").asText()); Assert.assertEquals(result.benchmarkRounds, resultNode.get("benchmarkRounds").asInt()); Assert.assertEquals(result.warmupRounds, resultNode.get("warmupRounds").asInt()); Assert.assertEquals(result.warmupTime, resultNode.get("warmupTime").asInt()); Assert.assertEquals(result.benchmarkTime, resultNode.get("benchmarkTime").asInt()); Assert.assertTrue(resultNode.get("roundAverage").isObject()); final ObjectNode roundAverageNode = (ObjectNode) resultNode.get("roundAverage"); Assert.assertEquals(result.roundAverage.avg, roundAverageNode.get("avg").asDouble(), 0.0001d); Assert.assertEquals(result.roundAverage.stddev, roundAverageNode.get("stddev").asDouble(), 0.0001d); Assert.assertTrue(resultNode.get("blockedAverage").isObject()); final ObjectNode blockedAverageNode = (ObjectNode) resultNode.get("blockedAverage"); Assert.assertEquals(result.blockedAverage.avg, blockedAverageNode.get("avg").asDouble(), 0.0001d); Assert.assertEquals(result.blockedAverage.stddev, blockedAverageNode.get("stddev").asDouble(), 0.0001d); Assert.assertTrue(resultNode.get("gcAverage").isObject()); final ObjectNode gcAverageNode = (ObjectNode) resultNode.get("gcAverage"); Assert.assertEquals(result.gcAverage.avg, gcAverageNode.get("avg").asDouble(), 0.0001d); Assert.assertEquals(result.gcAverage.stddev, gcAverageNode.get("stddev").asDouble(), 0.0001d); Assert.assertTrue(resultNode.get("gcInfo").isObject()); final ObjectNode gcInfoNode = (ObjectNode) resultNode.get("gcInfo"); Assert.assertEquals(result.gcInfo.accumulatedInvocations(), gcInfoNode.get("accumulatedInvocations").asInt()); Assert.assertEquals(result.gcInfo.accumulatedTime(), gcInfoNode.get("accumulatedTime").asInt()); Assert.assertEquals(result.getThreadCount(), resultNode.get("threadCount").asInt()); }
From source file:com.gitpitch.services.DiskService.java
public void deepDelete(PitchParams pp, String target) { Path branchPath = asPath(pp, target); deepDelete(branchPath.toFile()); }
From source file:com.netflix.spinnaker.halyard.backup.services.v1.BackupService.java
private void untarHalconfig(String halconfigDir, String halconfigTar) { FileInputStream tarInput = null; TarArchiveInputStream tarArchiveInputStream = null; try {/*ww w. jav a 2 s .c o m*/ tarInput = new FileInputStream(new File(halconfigTar)); tarArchiveInputStream = (TarArchiveInputStream) new ArchiveStreamFactory() .createArchiveInputStream("tar", tarInput); } catch (IOException | ArchiveException e) { throw new HalException(Problem.Severity.FATAL, "Failed to open backup: " + e.getMessage(), e); } try { ArchiveEntry archiveEntry = tarArchiveInputStream.getNextEntry(); while (archiveEntry != null) { String entryName = archiveEntry.getName(); Path outputPath = Paths.get(halconfigDir, entryName); File outputFile = outputPath.toFile(); if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } if (archiveEntry.isDirectory()) { outputFile.mkdir(); } else { Files.copy(tarArchiveInputStream, outputPath, REPLACE_EXISTING); } archiveEntry = tarArchiveInputStream.getNextEntry(); } } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Failed to read archive entry: " + e.getMessage(), e); } }
From source file:ch.ifocusit.livingdoc.plugin.publish.HtmlPostProcessor.java
public String getPageTitle(Path path) { String pageContent = null;/* ww w. j av a2 s . c o m*/ try { pageContent = IOUtils.readFull(new FileInputStream(path.toFile())); } catch (FileNotFoundException e) { throw new IllegalStateException("Unable to read page title !", e); } try { if (isAdoc(path)) { return getTitle(asciidoctor, pageContent).orElseThrow( () -> new IllegalStateException("top-level heading or title meta information must be set")); } // try to read h1 tag return tagText(pageContent, "h1"); } catch (IllegalStateException e) { return FilenameUtils.removeExtension(path.getFileName().toString()); } }