List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:org.fcrepo.importexport.integration.BagItIT.java
@Test public void testExportBag() throws Exception { final String exampleID = UUID.randomUUID().toString(); final URI uri = URI.create(serverAddress + exampleID); final FcrepoResponse response = create(uri); assertEquals(SC_CREATED, response.getStatusCode()); assertEquals(uri, response.getLocation()); final Config config = new Config(); config.setMode("export"); config.setBaseDirectory(TARGET_DIR + File.separator + exampleID); config.setIncludeBinaries(true);//from w ww. j a va 2 s . c o m config.setResource(uri); config.setPredicates(new String[] { CONTAINS.toString() }); config.setRdfExtension(DEFAULT_RDF_EXT); config.setRdfLanguage(DEFAULT_RDF_LANG); config.setUsername(USERNAME); config.setPassword(PASSWORD); config.setBagProfile(DEFAULT_BAG_PROFILE); config.setBagConfigPath("src/test/resources/configs/bagit-config.yml"); new Exporter(config, clientBuilder).run(); final Path target = Paths.get(TARGET_DIR, exampleID); assertTrue(target.resolve("bagit.txt").toFile().exists()); assertTrue(target.resolve("manifest-sha1.txt").toFile().exists()); final Path dataDir = target.resolve("data"); assertTrue(dataDir.toFile().exists()); assertTrue(dataDir.toFile().isDirectory()); final Path resourceFile = Paths.get(dataDir.toString(), uri.getPath() + DEFAULT_RDF_EXT); assertTrue(resourceFile.toFile().exists()); final FcrepoResponse response1 = clientBuilder.build().get(uri).perform(); final MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); final byte[] buf = new byte[8192]; int read = 0; while ((read = response1.getBody().read(buf)) != -1) { sha1.update(buf, 0, read); } final String checksum = new String(encodeHex(sha1.digest())); final BufferedReader reader = new BufferedReader( new FileReader(target.resolve("manifest-sha1.txt").toFile())); final String checksumLine = reader.readLine(); reader.close(); assertEquals(checksum, checksumLine.split(" ")[0]); }
From source file:com.liferay.sync.engine.BaseTestCase.java
@After public void tearDown() throws Exception { Path filePath = Paths.get(filePathName); FileUtils.deleteDirectory(filePath.toFile()); SyncAccountService.deleteSyncAccount(syncAccount.getSyncAccountId()); }
From source file:com.codealot.textstore.FileStore.java
@Override public long getLength(final String id) throws IOException { checkId(id);/* w w w. j av a2s.co m*/ final Path textPath = idToPath(id); return textPath.toFile().length(); }
From source file:com.spotify.helios.ZooKeeperStandaloneServerManager.java
public void backup(final Path destination) { try {//from www.ja v a 2 s .co m FileUtils.copyDirectory(dataDir, destination.toFile()); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:org.fedoraproject.copr.client.impl.HttpMock.java
@Override public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { String uri = request.getRequestLine().getUri(); String resourceName;/*ww w . ja va 2s. com*/ try { String method = request.getRequestLine().getMethod(); if (method.equals("GET")) { resourceName = test.getMock().get(uri); } else if (method.equals("POST")) { resourceName = test.getMock().post(uri); } else { fail("Unexpected method: " + method); throw new RuntimeException(); } if (resourceName == null) { response.setStatusCode(SC_NOT_FOUND); } else { Path resourcePath = Paths.get("src/test/resources").resolve(resourceName + ".json"); response.setStatusCode(SC_OK); response.setEntity(new FileEntity(resourcePath.toFile(), APPLICATION_JSON)); } } catch (Exception e) { response.setStatusCode(SC_INTERNAL_SERVER_ERROR); } }
From source file:de.zalando.awsqueen.awqfetch.FetchCLI.java
@Override public void run(final String... args) { try {//from w w w . j a v a 2 s . co m checkArgument(args.length == 1, "Number of arguments must be exactly 1"); } catch (final IllegalArgumentException e) { System.out.println(e.getMessage() + " Usage:\n" // + "run.sh <service>"); } final String service = args[0]; Path currentDirPath = Paths.get(currentDir); Region region = null; try { region = Region.getRegion(Regions.fromName(currentDirPath.toFile().getName())); } catch (final IllegalArgumentException e) { System.out.println("Region " + currentDir + " not found in AWS"); } if (region == null) { System.exit(1); } try { switch (service) { case "ec2": fetchEC2(region); break; case "elb": System.out.println("elb"); break; default: break; } } catch (final IllegalArgumentException e) { System.out.println(e.getMessage() + " Usage:\n" // + "run.sh <service>"); } }
From source file:com.vmware.admiral.adapter.docker.service.SystemImageRetrievalManager.java
private void getExternalAgentImage(String resourcesPath, String containerImage, Consumer<byte[]> callback) { Path imageResourcePath = Paths.get(resourcesPath, SYSTEM_IMAGES_PATH, containerImage); File file = imageResourcePath.toFile(); if (!file.exists()) { callback.accept(null);/*from ww w.ja v a 2 s . c om*/ return; } Operation operation = new Operation(); operation.setCompletion((op, ex) -> { if (op.hasBody()) { callback.accept(op.getBody(new byte[0].getClass())); } else { callback.accept(null); } }); FileUtils.readFileAndComplete(operation, file); }
From source file:com.nike.cerberus.command.validator.UploadCertFilesPathValidator.java
@Override public void validate(final String name, final Path value) throws ParameterException { if (value == null) { throw new ParameterException("Value must be specified."); }//from w w w . j a va 2 s . co m final File certDirectory = value.toFile(); final Set<String> filenames = Sets.newHashSet(); if (!certDirectory.canRead()) { throw new ParameterException("Specified path is not readable."); } if (!certDirectory.isDirectory()) { throw new ParameterException("Specified path is not a directory."); } final FilenameFilter filter = new RegexFileFilter("^.*\\.pem$"); final File[] files = certDirectory.listFiles(filter); Arrays.stream(files).forEach(file -> filenames.add(file.getName())); if (!filenames.containsAll(EXPECTED_FILE_NAMES)) { final StringJoiner sj = new StringJoiner(", ", "[", "]"); EXPECTED_FILE_NAMES.stream().forEach(sj::add); throw new ParameterException("Not all expected files are present! Expected: " + sj.toString()); } }
From source file:com.offbynull.coroutines.antplugin.InstrumentTask.java
private void instrumentPath(Instrumenter instrumenter) throws IOException { for (File inputFile : FileUtils.listFiles(sourceDirectory, new String[] { "class" }, true)) { Path relativePath = sourceDirectory.toPath().relativize(inputFile.toPath()); Path outputFilePath = targetDirectory.toPath().resolve(relativePath); File outputFile = outputFilePath.toFile(); log("Instrumenting " + inputFile, Project.MSG_INFO); byte[] input = FileUtils.readFileToByteArray(inputFile); byte[] output = instrumenter.instrument(input); log("File size changed from " + input.length + " to " + output.length, Project.MSG_DEBUG); FileUtils.writeByteArrayToFile(outputFile, output); }/*from w ww .j av a 2 s .com*/ }
From source file:fr.inria.atlanmod.neoemf.data.AbstractPersistenceBackendFactory.java
/** * Creates and saves the NeoEMF configuration. * * @param directory the directory where the configuration must be stored. *///from ww w. j av a 2s.co m protected void processGlobalConfiguration(File directory) throws InvalidDataStoreException { PropertiesConfiguration configuration; Path path = Paths.get(directory.getAbsolutePath()).resolve(CONFIG_FILE); try { configuration = new PropertiesConfiguration(path.toFile()); } catch (ConfigurationException e) { throw new InvalidDataStoreException(e); } if (!configuration.containsKey(BACKEND_PROPERTY)) { configuration.setProperty(BACKEND_PROPERTY, getName()); } try { configuration.save(); NeoLogger.debug("Configuration stored at " + path); } catch (ConfigurationException e) { /* * Unable to save configuration. * Supposedly it's a minor error, so we log it without rising an exception. */ NeoLogger.warn(e); } }