List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:org.openlmis.fulfillment.service.OrderFtpSender.java
private boolean send(Order order, Path path, FtpTransferProperties ftp) { try {/*from w ww .jav a 2s .c o m*/ String endpointUri = createEndpointUri(ftp); File file = path.toFile(); producerTemplate.sendBodyAndHeader(endpointUri, file, Exchange.FILE_NAME, file.getName()); } catch (Exception exp) { LOGGER.error("Can't transfer CSV file {} related with order {} to the FTP server", path, order.getId(), exp); return false; } return true; }
From source file:com.marklogic.entityservices.examples.ExamplesBase.java
private void importOrDescend(Path directory, WriteHostBatcher batcher, String collection, Format format) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) { for (Path entry : stream) { if (entry.toFile().isDirectory()) { logger.info("Reading subdirectory " + entry.getFileName().toString()); importOrDescend(entry, batcher, collection, format); } else { logger.debug("Adding " + entry.getFileName().toString()); String uri = entry.toUri().toString(); if (collection != null) { DocumentMetadataHandle metadata = new DocumentMetadataHandle().withCollections(collection) // .withPermission("race-reader", Capability.READ) // .withPermission("race-writer", Capability.INSERT, Capability.UPDATE); batcher.add(uri, metadata, new FileHandle(entry.toFile()).withFormat(format)); } else { batcher.add(uri, new FileHandle(entry.toFile()).withFormat(format)); }//w ww. ja v a 2s . com logger.debug("Inserted " + format.toString() + " document " + uri); } } } catch (IOException e) { e.printStackTrace(); } }
From source file:cool.pandora.modeller.ui.handlers.iiif.UploadBagHandler.java
@Override public void execute() { final String message = ApplicationContextUtil.getMessage("bag.message.fileuploaded"); final DefaultBag bag = bagView.getBag(); final List<String> payload = bag.getPayloadPaths(); final Map<String, BagInfoField> map = bag.getInfo().getFieldMap(); 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 URI destinationURI = IIIFObjectURI.getDestinationURI(map, filename); final Path absoluteFilePath = rootDir.resolve(filePath); final File resourceFile = absoluteFilePath.toFile(); try {/*w ww . ja v a 2 s.c o m*/ final InputStream targetStream = new FileInputStream(resourceFile); final String contentType = ImageIOUtil.getImageMIMEType(resourceFile); try { ModellerClient.doStreamPut(destinationURI, targetStream, contentType); ApplicationContextUtil.addConsoleMessage(message + " " + destinationURI); } catch (final ModellerClientFailedException e) { ApplicationContextUtil.addConsoleMessage(getMessage(e)); } } catch (FileNotFoundException e) { e.printStackTrace(); } } bagView.getControl().invalidate(); }
From source file:com.netflix.spinnaker.halyard.config.config.v1.HalconfigDirectoryStructure.java
public Path getInstallScriptPath(String deploymentName) { Path halconfigPath = Paths.get(halconfigDirectory, deploymentName); ensureDirectory(halconfigPath);//from w w w . j av a 2 s . c om return new File(halconfigPath.toFile(), "install.sh").toPath(); }
From source file:com.netflix.spinnaker.halyard.config.config.v1.HalconfigDirectoryStructure.java
public Path getConnectScriptPath(String deploymentName) { Path halconfigPath = Paths.get(halconfigDirectory, deploymentName); ensureDirectory(halconfigPath);/*www . j a v a 2 s . c o m*/ return new File(halconfigPath.toFile(), "connect.sh").toPath(); }
From source file:com.dancorder.Archiverify.Parameters.java
private void validatePath(Path path) throws Exception { if (!path.toFile().exists() || !path.toFile().isDirectory()) { throw new Exception("Path must be an existing directory: " + path); }/* ww w .j a v a 2s .co m*/ }
From source file:org.sakuli.starter.helper.SahiProxy.java
private boolean isNewer(Path source, Path target) { return !Files.exists(target) || FileUtils.isFileNewer(source.toFile(), target.toFile()); }
From source file:fi.jumi.launcher.daemon.DirBasedStewardTest.java
@Test public void overwrites_an_existing_daemon_JAR_that_has_difference_file_size() throws IOException { overwriteWithFileOfSize(expectedContent.length + 1, steward.getDaemonJar(jumiHome)); Path daemonJar = steward.getDaemonJar(jumiHome); assertThat(FileUtils.readFileToByteArray(daemonJar.toFile()), is(expectedContent)); }
From source file:io.github.swagger2markup.GeneralConverterTest.java
@Test public void testFromHttpURI() throws IOException, URISyntaxException { //Given/*w w w.j a v a 2 s.c o m*/ Path outputDirectory = Paths.get("build/test/asciidoc/fromUri"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(URI.create("http://petstore.swagger.io/v2/swagger.json")).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); }
From source file:io.github.swagger2markup.GeneralConverterTest.java
@Test public void testFromResourceURI() throws IOException, URISyntaxException { //Given//from ww w.j a v a 2s .co m Path outputDirectory = Paths.get("build/test/asciidoc/fileUri"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(GeneralConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()) .build().toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); }