List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:io.github.swagger2markup.GeneralConverterTest.java
@Test public void testFromPathURI() throws IOException, URISyntaxException { //Given/* w ww .j a v a 2s . c o m*/ Path outputDirectory = Paths.get("build/test/asciidoc/pathUri"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(Paths.get("src/test/resources/yaml/swagger_petstore.yaml").toUri()).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 testFromStringURIWithoutScheme() throws IOException, URISyntaxException { //Given//from ww w . ja v a 2s .co m Path outputDirectory = Paths.get("build/test/asciidoc/pathUri"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(URI.create("src/test/resources/yaml/swagger_petstore.yaml")).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 testFromURL() throws IOException, URISyntaxException { //Given/* ww w . j a va2 s . co m*/ Path outputDirectory = Paths.get("build/test/asciidoc/fromUrl"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConverter.from(new URL("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:com.artglorin.web.utils.ResourcesHelper.java
/** * ? ?? .//from w w w . j a v a 2 s .c om * ? * * @param data ?? , ?. * @param path ? . ??, . ? * ?, ? ? ? ?. ? ? ?? ? * ["data","file",".txt"], ? "/pathToResources/data/file.txt". * ? ?? ["data","file.txt"] ? "/data/file.txt", * ? "/pathToResources/data/file.txt" * @throws IOException */ public void saveData(byte[] data, String... path) throws IOException { if (path.length == 0) { throw new IOException("Path cannot be null"); } Path file = createRealPath(path); String[] filePath = null; if (file.toFile().exists()) { FileUtils.writeByteArrayToFile(file.toFile(), data); } else { if (path.length > 1) { if (path[path.length - 1].startsWith(".")) { filePath = Arrays.copyOf(path, path.length - 2); } } } if (filePath == null) { filePath = Arrays.copyOf(path, path.length - 1); } createResourcesDirectory(filePath); FileUtils.writeByteArrayToFile(file.toFile(), data); }
From source file:com.shazam.fork.system.io.FileManager.java
public File getFile(FileType fileType, String pool, String safeSerial, TestIdentifier testIdentifier) { String filenameForTest = createFilenameForTest(testIdentifier, fileType); Path path = get(output.getAbsolutePath(), fileType.getDirectory(), pool, safeSerial, filenameForTest); return path.toFile(); }
From source file:com.marklogic.entityservices.e2e.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("nwind-reader", Capability.READ) // .withPermission("nwind-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 w w . j av a 2 s . c o m*/ logger.debug("Inserted " + format.toString() + " document " + uri); } } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.arpnetworking.tsdaggregator.perf.CollectdPipelineTest.java
@Test public void test() throws IOException, InterruptedException, URISyntaxException { // Extract the sample file final Path gzipPath = Paths.get("build/resources/perf/collectd-sample1.log.gz"); final FileInputStream fileInputStream = new FileInputStream(gzipPath.toFile()); final GZIPInputStream gzipInputStream = new GZIPInputStream(fileInputStream); final Path path = Paths.get("build/tmp/perf/collectd-sample1.log"); final FileOutputStream outputStream = new FileOutputStream(path.toFile()); IOUtils.copy(gzipInputStream, outputStream); benchmark(new File(Resources.getResource("collectd_sample1_pipeline.json").toURI()), Duration.standardMinutes(20)); }
From source file:com.netflix.spinnaker.halyard.core.registry.v1.GitProfileReader.java
@Override public InputStream readArchiveProfile(String artifactName, String version, String profileName) throws IOException { Path profilePath = Paths.get(profilePath(artifactName, version, profileName)); ByteArrayOutputStream os = new ByteArrayOutputStream(); TarArchiveOutputStream tarArchive = new TarArchiveOutputStream(os); ArrayList<Path> filePathsToAdd = java.nio.file.Files .walk(profilePath, Integer.MAX_VALUE, FileVisitOption.FOLLOW_LINKS) .filter(path -> path.toFile().isFile()).collect(Collectors.toCollection(ArrayList::new)); for (Path path : filePathsToAdd) { TarArchiveEntry tarEntry = new TarArchiveEntry(path.toFile(), profilePath.relativize(path).toString()); int permissions = FileModeUtils.getFileMode(Files.getPosixFilePermissions(path)); permissions = FileModeUtils.setFileBit(permissions); tarEntry.setMode(permissions);//from w w w .j a v a 2 s. c o m tarArchive.putArchiveEntry(tarEntry); IOUtils.copy(Files.newInputStream(path), tarArchive); tarArchive.closeArchiveEntry(); } tarArchive.finish(); tarArchive.close(); return new ByteArrayInputStream(os.toByteArray()); }
From source file:fi.jumi.launcher.daemon.DirBasedStewardTest.java
@Test public void throws_exception_if_cannot_create_daemon_directory() throws IOException { Path parentDir = steward.createDaemonDir(jumiHome).getParent(); FileUtils.deleteDirectory(parentDir.toFile()); Files.createFile(parentDir); // prevents it from creating the daemon directory thrown.expect(RuntimeException.class); thrown.expectMessage("Unable to create daemon directory"); thrown.expectCause(instanceOf(FileAlreadyExistsException.class)); steward.createDaemonDir(jumiHome);// w ww. j a va 2 s.c o m }
From source file:br.com.caelum.vraptor.observer.upload.CommonsUploadedFile.java
@Override public void writeTo(Path target, CopyOption... options) throws IOException { requireNonNull(target, TARGET_CANNOT_BE_NULL); writeTo(target.toFile()); }