List of usage examples for java.nio.file Path getParent
Path getParent();
From source file:dk.ekot.misc.SynchronizedCache.java
protected void copy(Path fullSourcePath, Path fullCachePath) throws IOException { Files.createDirectories(fullCachePath.getParent()); Files.copy(fullSourcePath, fullCachePath, StandardCopyOption.REPLACE_EXISTING); }
From source file:com.zergiu.tvman.controllers.FSBrowseController.java
/** * @param children//from w ww. j ava2 s . co m * @param parent */ private void addParentFolder(Map<String, String> children, Path parent) { Path parentOfParent = parent.getParent(); if (parentOfParent == null) { children.put("", ".."); } else { children.put(parentOfParent.toString(), ".."); } }
From source file:org.bonitasoft.platform.configuration.util.AllConfigurationResourceVisitor.java
private boolean isConfigurationFile(Path path) { final Path parentFolder = path.getParent(); return path.toFile().isFile() && (isTenantFolder(parentFolder) || isPlatformFolder(parentFolder)); }
From source file:org.aksw.gerbil.datasets.DatahubNIFConfig.java
/** * We have to synchronize this method. Otherwise every experiment thread would check the file and try to download * the data or try to use the file even the download hasn't been completed. *///from w w w . j av a 2s. co m @Override protected synchronized TopicDataset loadDataset() throws Exception { String nifFile = GerbilConfiguration.getInstance().getString(DATAHUB_DATASET_FILE_PROPERTY_NAME) + getName(); logger.debug("FILE {}", nifFile); File f = new File(nifFile); if (!f.exists()) { logger.debug("file {} does not exist. need to download", nifFile); String data = rt.getForObject(datasetUrl, String.class); Path path = Paths.get(nifFile); Files.createDirectories(path.getParent()); Path file = Files.createFile(path); Files.write(file, data.getBytes(), StandardOpenOption.WRITE); } FileBasedNIFDataset dataset = new FileBasedNIFDataset(wikiApi, nifFile, getName(), Lang.TTL); dataset.init(); return dataset; }
From source file:io.sloeber.core.managers.Manager.java
/** * Given a platform description in a json file download and install all * needed stuff. All stuff is including all tools and core files and * hardware specific libraries. That is (on windows) inclusive the make.exe * * @param platform/* w ww . j a v a 2s . c o m*/ * @param monitor * @param object * @return */ static public IStatus downloadAndInstall(ArduinoPlatform platform, boolean forceDownload, IProgressMonitor monitor) { IStatus status = downloadAndInstall(platform.getUrl(), platform.getArchiveFileName(), platform.getInstallPath(), forceDownload, monitor); if (!status.isOK()) { return status; } MultiStatus mstatus = new MultiStatus(status.getPlugin(), status.getCode(), status.getMessage(), status.getException()); if (platform.getToolsDependencies() != null) { for (ToolDependency tool : platform.getToolsDependencies()) { monitor.setTaskName(InstallProgress.getRandomMessage()); mstatus.add(tool.install(monitor)); } } // On Windows install make from equations.org if (Platform.getOS().equals(Platform.OS_WIN32)) { try { Path makePath = Paths .get(ConfigurationPreferences.getPathExtensionPath().append("make.exe").toString()); //$NON-NLS-1$ if (!makePath.toFile().exists()) { Files.createDirectories(makePath.getParent()); URL makeUrl = new URL("ftp://ftp.equation.com/make/32/make.exe"); //$NON-NLS-1$ Files.copy(makeUrl.openStream(), makePath); makePath.toFile().setExecutable(true, false); } } catch (IOException e) { mstatus.add(new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Downloading_make_exe, e)); } } return mstatus.getChildren().length == 0 ? Status.OK_STATUS : mstatus; }
From source file:org.metaservice.frontend.rest.cache.FileSystemCacheResourceService.java
private InputStream cacheResource(InputStream inputStream, String resource, String mimetype) throws IOException { byte[] content = org.apache.commons.io.IOUtils.toByteArray(inputStream); Path source = Files.createTempFile(DigestUtils.md5Hex(resource), getExtension(mimetype)); try (OutputStream outputStream = new FileOutputStream(source.toFile())) { IOUtils.write(content, outputStream); }/* w w w . j a v a 2s . com*/ Path target = getCacheFile(resource, mimetype).toPath(); if (!target.getParent().toFile().isDirectory()) { Files.createDirectories(target.getParent()); } Files.move(source, target, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); return new ByteArrayInputStream(content); }
From source file:org.bonitasoft.platform.configuration.util.AllConfigurationResourceVisitor.java
private Long getTenantId(Path dir) { try {/*from w w w. j a va 2s .c om*/ return Long.parseLong(dir.getParent().getFileName().toString()); } catch (NumberFormatException e) { return 0L; } }
From source file:gndata.lib.config.AbstractConfig.java
/** * Serializes the config to json and writes it to a file. The method uses {@link #getFilePath()} * for storing the configuration.//from w w w .ja v a 2s .c om * * @throws IOException If the storing of the configuration failed. */ public void store() throws IOException { Path tmpPath = Paths.get(filePath); Files.createDirectories(tmpPath.getParent()); try { ObjectMapper mapper = new ObjectMapper().enable(INDENT_OUTPUT).disable(FAIL_ON_EMPTY_BEANS); mapper.writeValue(tmpPath.toFile(), this); } catch (IOException e) { throw new IOException("Unable to write configuration file: " + this.filePath, e); } }
From source file:com.diffplug.gradle.GradleIntegrationTest.java
protected void write(String path, String... lines) throws IOException { String content = Arrays.asList(lines).stream().collect(Collectors.joining("\n")) + "\n"; Path target = folder.getRoot().toPath().resolve(path); Files.createDirectories(target.getParent()); Files.write(target, content.getBytes(StandardCharsets.UTF_8)); }
From source file:org.hara.sodra.utils.SodraUtilsTest.java
@After public void tearDown() throws Exception { Path solrHome = Paths.get(TEST_SODRA_HOME); FileUtils.deleteDirectory(solrHome.getParent().toFile()); }