List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:com.netflix.spinnaker.halyard.config.config.v1.HalconfigDirectoryStructure.java
private void ensureDirectory(Path path) { File file = path.toFile(); if (file.exists()) { if (!file.isDirectory()) { throw new HalException( new ConfigProblemBuilder(Problem.Severity.FATAL, "The path " + path + " may not be a file.") .setRemediation( "Please backup the file and remove it from your halconfig directory.") .build());/* w ww . j a va2s .co m*/ } } else { try { if (!file.mkdirs()) { throw new HalException(new ConfigProblemBuilder(Problem.Severity.FATAL, "Error creating the directory " + path + " with unknown reason.").build()); } } catch (Exception e) { throw new HalException(new ConfigProblemBuilder(Problem.Severity.FATAL, "Error creating the directory " + path + ": " + e.getMessage()).build()); } } }
From source file:com.arcanix.php.phar.DirectoryPharEntryProvider.java
private void addPharEntriesRecursively(final List<PharEntry> pharEntries, final Path directory) throws IOException { try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) { for (Path element : directoryStream) { File file = element.toFile(); if (file.isDirectory()) { addPharEntriesRecursively(pharEntries, element); } else { String relativePath = this.rootPath.relativize(element).toString(); pharEntries.add(new PharEntry(file, this.localPath + "/" + relativePath, this.pharCompression)); }//from w w w . j a va2 s . co m } } }
From source file:org.trustedanalytics.uploader.UploaderConfigurationLocal.java
@Bean public InFolderObjectStore inFolderObjectStore() { Path path = Paths.get(System.getProperty("user.dir"), "target", "uploads"); path.toFile().mkdirs(); return new InFolderObjectStore(path.toString()); }
From source file:com.hortonworks.registries.schemaregistry.avro.AvroSchemaRegistryClientWithConfFileTest.java
@Before public void setup() throws IOException { Path confFilePath = Files.createTempFile("sr-client-conf", ".props"); File confFile = confFilePath.toFile(); try (FileOutputStream fos = new FileOutputStream(confFile); InputStream fis = this.getClass().getResourceAsStream("/schema-registry-client.yaml")) { String confText = IOUtils.toString(fis, "UTF-8").replace("__registry_url", rootUrl); IOUtils.write(confText, fos, "UTF-8"); }//from w ww. j a v a 2s .c o m schemaRegistryClient = new SchemaRegistryClient(confFile); }
From source file:edu.jhu.hlt.acute.archivers.zip.ZipArchiver.java
/** * Wrap an {@link Path} that represents a * <code>.zip</code> file. This constructor be used when writing to files on disk. * //from w w w . j a va2 s .c om * @throws IOException */ public ZipArchiver(Path path) throws IOException { this.zout = new ZipArchiveOutputStream(path.toFile()); }
From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java
static void saveHistograms(ArrayList<double[][][]> hists, Path outfile) { int w_d = hists.get(0).length; int h_d = hists.get(0)[0].length; int o_d = hists.get(0)[0][0].length; int i, j, k, l; try (FileOutputStream fos = new FileOutputStream(outfile.toFile()); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos))) { String head = String.format("%d %d", hists.size(), w_d * h_d * o_d); writer.write(head);// ww w. ja va 2 s. c o m writer.newLine(); for (l = 0; l < (int) hists.size(); l++) { double[][][] hist = hists.get(l); for (i = 0; i < hist.length; i++) { for (j = 0; j < hist[0].length; j++) { for (k = 0; k < hist[0][0].length; k++) { // optical_bins+1 writer.write(String.format("%f ", hist[i][j][k])); } } } writer.newLine(); } } catch (IOException x) { System.err.println(x); } }
From source file:de.zalando.awsqueen.awqfetch.FetchCLI.java
private void fetchEC2(final Region region) { Path ec2Path = Paths.get(currentDir, "ec2"); ec2Path.toFile().mkdir(); AmazonEC2Client amazonEC2Client = new AmazonEC2Client(); amazonEC2Client.setRegion(region);/*from ww w . ja v a 2s .c om*/ DescribeInstancesResult describeInstancesResult = amazonEC2Client.describeInstances(); List<Reservation> reservations = describeInstancesResult.getReservations(); for (Reservation reservation : reservations) { List<Instance> instances = reservation.getInstances(); for (Instance instance : instances) { System.out.println("instance id: " + instance.getInstanceId()); } } }
From source file:com.shazam.fork.system.io.FileManager.java
private File createFile(Path directory, String filename) { return new File(directory.toFile(), filename); }
From source file:pzalejko.iot.hardware.home.core.service.DefaultTemperatureService.java
private double loadTemperatureFromFile(String directory, String fileName) { final Path path = Paths.get(directory, fileName); if (path.toFile().exists()) { try (Stream<String> lines = Files.lines(path)) { // @formatter:off return lines.filter(s -> s.contains(TEMP_MARKER)).map(TEMPERATURE_VALUE_EXTRACTOR::apply) .findFirst().orElse(Double.NaN); // @formatter:on } catch (final IOException | NumberFormatException e) { LOG.error(LogMessages.COULD_NOT_COLLECT_A_TEMPERATURE, e.getMessage(), e); }/*from w ww.j a va2 s . c o m*/ } else { LOG.warn(LogMessages.COULD_NOT_COLLECT_TEMPERATURE_MISSING_SOURCE, path.toAbsolutePath()); } return Double.NaN; }
From source file:com.shazam.fork.system.io.FileManager.java
public File[] getTestFilesForDevice(Pool pool, Device serial) { Path path = getDirectory(TEST, pool, serial); return path.toFile().listFiles(); }